Intent的应用(一):隐式意图和显式意图
2017-11-21 22:59
357 查看
* 显式意图
能从intent上直观的看到跳转到哪一个界面
应用场景: 一般是自己内部跳转的时候,用显式意图 效率高
* 隐式意图
要指定action(动作) 、data(数据) 来达到跳转的目的
应用场景:一般是跳转到其他应用中的某个界面,或者自己的应用界面想被其他应用打开。 效率低
第一步:编写布局XML文件和Activity文件
第二步:在清单文件中注册Activity
第三步:跳转
第一步:编写布局XML文件和Activity文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#33ff0000"
android:orientation="vertical" >
<TextView
android:text="隐式跳转的界面"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
</LinearLayout>
第三步:跳转
能从intent上直观的看到跳转到哪一个界面
应用场景: 一般是自己内部跳转的时候,用显式意图 效率高
* 隐式意图
要指定action(动作) 、data(数据) 来达到跳转的目的
应用场景:一般是跳转到其他应用中的某个界面,或者自己的应用界面想被其他应用打开。 效率低
第一步:编写布局XML文件和Activity文件
第二步:在清单文件中注册Activity
第三步:跳转
第一步:编写布局XML文件和Activity文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#33ff0000"
android:orientation="vertical" >
<TextView
android:text="隐式跳转的界面"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
</LinearLayout>
package com.heima.testIntent; import android.app.Activity; import android.os.Bundle; public class FirstActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.first_second); } }第二步:在清单文件中注册Activity
<!-- 显式意图注册 --> <activity android:name="com.heima.testIntent.SecondActivity"></activity> <!-- 隐式意图注册 --> <activity android:name="com.heima.testIntent.FirstActivity"> <!-- 意图过滤 器--> <!-- action和 category都必须写上 --> <intent-filter> <action android:name="com.heima.testIntent.action.bb"/> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>注意:只要activity中有<intent-filter>属性,那么该Activity能被其他应用程序访问
第三步:跳转
public void click01(View v) { //使用显式手法启动界面 Intent intent = new Intent(MainActivity.this,SecondActivity.class); startActivity(intent); } public void click02(View v) { //使用隐式手法启动02界面 Intent intent = new Intent(); intent.setAction("com.heima.testIntent.action.bb"); intent.addCategory("android.intent.category.DEFAULT"); startActivity(intent); }
相关文章推荐
- intent 显式意图和隐式意图
- Android显式意图、隐式意图、意图过滤器(intent-filter)、意图间传值
- Android中intent的作用,显式意图和隐式意图
- Android显式意图、隐式意图、意图过滤器(intent-filter)、意图间传值
- intent 显式意图以及隐式意图,在Activity、Service和Broadcastreceiver应用
- (转)Android开发:显式/隐式Intent意图跳转Activity总结
- Android开发:显式/隐式Intent意图跳转Activity总结
- Activity中Intent的含义以及显式意图与隐式意图区别
- Android开发:显式/隐式Intent意图跳转Activity总结
- Intent(显式意图,隐式意图)
- intent 显式意图和隐式意图之Activity的激活方式
- Android实例demo19之Intent显式意图隐式意图、隐式意图打开多个网页
- Android Studio Intent使用(显式、隐式) 第一行代码
- Intent之学习一(显式与隐式)
- [android] 隐式意图和显式意图的使用场景
- Android中intent的隐式意图
- Intent的显式与隐式
- Android:显式Intent和隐式Intent
- Android Intent隐式启动通过scheme打开应用
- 安卓四大组件之一#2-一使用Intent显式意图实现界面跳转以及数据传递