Android中 intent 显式启动与隐式启动
2017-04-14 21:47
288 查看
显式启动代码
FirstActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.first_layout); Button button1 = (Button) findViewById(R.id.button_1); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Toast.makeText(FirstActivity.this,"哈哈",Toast.LENGTH_SHORT).show(); Intent intent = new Intent(FirstActivity.this,SecondActivity.class); startActivity(intent); } }); }
隐式启动代码
清单文件
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".FirstActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SecondActivity"> <intent-filter> <action android:name="com.example.deligence.ACTION_START"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> </application>
<action> 标签中我们指明了当前活动可以响应com.example.deligence.ACTION_START
而<category>标签包含了一些附加信息,更精确地表明了当前活动能够响应的Intent中还可能带有的category.只有<action>和<category>中的内容
能同时匹配上intent指定的action和category时,这个活动才能响应改intent
FirstActivity.java
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.first_layout);Button button1 = (Button) findViewById(R.id.button_1);button1.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent("com.example.deligence.ACTION_START");startActivity(intent);}});}
android.intent.category.DEFAUL 是一种默认的category,再调用startActivity()方法的时候会自动将这个category添加到intent中
相关文章推荐
- android intent隐式调用之一个应用程序启动另一个应用程序
- android-Intent启动activity的几种方式-隐式Intent
- Android实例demo19之Intent显式意图隐式意图、隐式意图打开多个网页
- 隐式启动Activity,Intent filter必须添加android.intent.category.MAIN
- 隐式启动Activity,Intent filter必须添加android.intent.category.DEFAULT
- android intent隐式调用之一个应用程序启动另一个应用程序
- Android显式意图、隐式意图、意图过滤器(intent-filter)、意图间传值
- android学习记录(五)显式Intent与隐式Intent的功能与使用方法解析。
- Android显式意图、隐式意图、意图过滤器(intent-filter)、意图间传值
- [Android]Intent隐式启动Android系统程序的一些参数
- android intent隐式调用之一个应用程序启动另一个应用程序
- 隐式启动为什么要加android.intent.category.DEFAULT?
- Android理解:显式和隐式Intent
- android隐式intent及启动方式
- [转]Android 进程间通信 Intent机制 隐式启动Activity
- android intent隐式调用之一个应用程序启动另一个应用程序
- Intent隐式启动 AndroidManifest.xml 中的intent-filter
- Android学习篇章26-Intent显示与隐式启动
- Android Intent详细介绍及使用说明(显式、隐式和值传递)
- Android中Intent的详解(显式,隐式,系统,startActivityForResult);