码迷,mamicode.com
首页 > 移动开发 > 详细

Android生命周期

时间:2016-05-11 01:23:53      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:

1、Activity跳转

Intent intent = new Intent(MainActivity.this,NextActivity.class);
startActivity(intent);

跳转到NextActivity

2、带数据跳转

Intent intent = new Intent(MainActivity.this,NextActivity.class);
intent.putExtra("name","YinTing");
Bundle bundle = new Bundle();
bundle.putInt("age",22);
bundle.putChar("bood",‘b‘);
intent.putExtra("bundle",bundle);
startActivity(intent);

3、接收返回值跳转

Intent intent = new Intent(MainActivity.this,NextActivity.class);
intent.putExtra("name","YinTing");
Bundle bundle = new Bundle();
bundle.putInt("age",22);
bundle.putChar("bood",‘b‘);
intent.putExtra("bundle",bundle);
MainActivity.this.startActivityForResult(intent,1);

必须复写onActivityResult该方法。

 

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==1&&resultCode==1001){
String name= data.getStringExtra("name");
Toast.makeText(MainActivity.this,"---->"+name,Toast.LENGTH_LONG).show();
}

} NextActivity结束时带数据返回。


 

Intent intent=new Intent();
intent.putExtra("name","YangYi");
NextActivity.this.setResult(1001,intent);
NextActivity.this.finish();

4、Android生命周期

技术分享

5、Activity现场保护

技术分享

Android生命周期

标签:

原文地址:http://www.cnblogs.com/swordyt/p/5479878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!