- 1、本文档共85页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
第2章Android生命周期与组件通信分析
2.3.2 Intent形式 启动Activity 显式启动 使用Intent显式启动Activity 创建一个Intent 指定当前的应用程序上下文以及要启动的Activity 把创建好的这个Intent作为参数传递给startActivity()方法 Intent intent = new Intent(IntentDemo.this, ActivityToStart.class); startActivity(intent); * 举例:建立一个新的Android工程 工程名称:Chp02_IntentStartDirectly Activity名称:MainActivity,SecondActivity Intent显式启动SecondActivity * AndroidManifest.xml文件中声明Activity的代码如下: …… application android:icon=@drawable/icon“ android:label=@string/app_name 2 activity android:name=.MainActivity 3 android:label=@string/app_name 4 intent-filter 5 action android:name=ent.action.MAIN / 6 category android:name=ent.category.LAUNCHER / 7 /intent-filter 8 /activity 9 activity android:name=.SecondActivity 10 android:label=@string/app_name 11 /activity 12 /application …… 2.3.2 Intent形式 * MainActivity.java文件的代码 …… 1 public class MainActivity extends Activity { 2 private Button m_btnMainAct=null; 3 /** Called when the activity is first created. */ 4 @Override 5 public void onCreate(Bundle savedInstanceState) { 6 super.onCreate(savedInstanceState); 7 setContentView(R.layout.main); 8 m_btnMainAct=(Button)findViewById(R.id.btnMainAct); 9 m_btnMainAct.setOnClickListener(new OnClickListener(){ 10 public void onClick(View view){ 11 //声明一个Intent对象 12 Intent inttMainAct=new Intent(MainActivity.this,SecondActivity.class); 13 //Intent显示启动Activity 14 startActivity(inttMainAct); 15 } 16 }); 17 } 18 } …… * 2.3.2 Intent形式 代码12行采用了第五种构造函数形式,指明了主调组件MainActivity和目标组件SecondActivity。startActivity()方法启动Intent指向的Activity。上面代码使用了Activity显示启动的方式,直接指明了需要启动的Activity。 Intent类定义了六种构造函数。 Intent(); Intent(Intent o); Intent(String action); Inten
您可能关注的文档
- 第20章高效液相色谱分析.ppt
- 第2章-采购组织分析.ppt
- 琅岐葡萄节招商计划书解析.ppt
- 哈根达斯市场作业分析.doc
- 第2章-第1节-第2课时元素与物质的分类分析.ppt
- 第2章+地球空间与空间数据基础分析.ppt
- 理解性默写终极版解析.ppt
- 第2章-货币市场分析.ppt
- 理正基坑6.0杭州培训班教材解析.ppt
- 第2章-知识表示分析.ppt
- 2025年中国锻铁围栏市场调查研究报告.docx
- 2025年中国椭圆型市场调查研究报告.docx
- 2025年中国无蔗糖原味豆浆市场调查研究报告.docx
- 2025-2031年中国泛在电力物联网行业发展运行现状及投资潜力预测报告.docx
- 2025年中国制袋机零件市场调查研究报告.docx
- 2025年中国智能除垢型电子水处理仪市场调查研究报告.docx
- 2025-2031年中国甘肃省乡村旅游行业市场深度研究及投资策略研究报告.docx
- 2025-2031年中国干海产品行业市场发展监测及投资战略规划报告.docx
- 2025年中国全铝图解易拉盖市场调查研究报告.docx
- 2025年中国人造毛皮服装市场调查研究报告.docx
文档评论(0)