Activity(一)

[size=medium][b]How to start an Intent?[/b][/size]

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


Intent Intent = new Intent();
Intent.setComponent(new ComponentName(pkgName, activityName));


Intent Intent = new Intent();
Intent.setClassName(String pkgName, String activityName);


//Activity Send
Intent intent = new Intent(Intent.ACTION_SEND);
Intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.putExtra("apkpath", "/mnt/sdcard/apkinstall");
startActivity(intent);

//Activity Receive
Intent intent = getIntent();
intent.hasExra("apkpath");
String recevieValue = intent.getStringExtra("apkpath");

File file = new File(recevieValue);
if(file.exists()){
Toast.makeText(this, "OK", Toast.LENGTH_SHORT).show();
}



//Send
static final private int GET_CODE = 0;
startActivityForResult(intent, GET_CODE);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == GET_CODE){
if (resultCode == RESULT_CANCELED){}
else {System.out.println("data.getData() " + data.getAction());}
}
}

//Receive
setResult(RESULT_OK, (new Intent()).setAction("Corky!"));


[img]http://developer.android.com/images/activity_lifecycle.png[/img]

[size=medium][b]Saving activity state[/b][/size]
[img]http://developer.android.com/images/fundamentals/restore_instance.png[/img]
There's no guarantee that onSaveInstanceState() will be called before your activity is destroyed, If the system calls onSaveInstanceState(), it does so before onStop() and possibly before onPause().

Because the default implementation of onSaveInstanceState() helps save the state of the UI, if you override the method in order to save additional state information, you should always call the superclass implementation of onSaveInstanceState() before doing any work. Likewise, you should also call the supercall implementation of onRestoreInstanceState() if you override it, so the default implementation can restore view states.

A good way to test your application's ability to restore its state is to simply rotate the device so that the screen orientation changes.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值