Android中 intent 显式启动与隐式启动
来源:互联网 发布:梦幻古龙服务端源码 编辑:程序博客网 时间:2024/06/11 02:37
显式启动代码
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.javaprotected 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) { Intent intent = new Intent("com.example.deligence.ACTION_START"); startActivity(intent); } });}android.intent.category.DEFAUL 是一种默认的category,再调用startActivity()方法的时候会自动将这个category添加到intent中
1 0
- Android中 intent 显式启动与隐式启动
- Intent显示启动与隐式启动
- Android学习篇章26-Intent显示与隐式启动
- Intent隐式启动
- Intent隐式启动
- Android Intent隐式启动中android.intent.category.DEFAULT的必要性
- Android Activity Intent隐式启动
- Android隐式启动:Intent的用法
- Android隐式启动intent-filter详解
- #Intent的隐式启动和显式启动
- Intent显式启动和隐式启动
- Android显式启动与隐式启动Activity
- android显式启动与隐式启动
- Android进阶之Intent Filter匹配规则与隐式启动Activity
- 隐式启动为什么要加android.intent.category.DEFAULT?
- Android 进程间通信 Intent机制 隐式启动Activity
- Android Intent隐式启动通过scheme打开应用
- Android 5.0之后使用隐式Intent方式启动Service
- zero-copy零拷贝
- 数组中有一个数字出现一次,其余数字均出现两次,求出出现一次的那个数字。
- CF贪心刷题记录
- Python多线程爬取QQ音乐的专辑信息
- 相关性计算
- Android中 intent 显式启动与隐式启动
- HTML5新增表单元素
- LeetCode064 Minimum Path Sum
- 多线程系列提高(4)--同步容器类
- 1006. 换个格式输出整数 (15)
- 线程同步工具之CountDownLatch
- 登山
- 2017/4/15 Twosat介绍
- github上传本地代码失败