OnNewIntent 的调用,SingleStask 单例模式的Activity 当遇到新的Intent的时候,不会走onCreate方法了

public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   processExtraData();
 }


 protected void onNewIntent(Intent intent) {
   super.onNewIntent(intent);
   setIntent(intent);//must store the new intent unless getIntent() will return the old one
   processExtraData()
 }


 private void processExtraData(){
   Intent intent = getIntent();
   //use the data received here
 }


OnNewIntent 的调用:

单例模式(SingleStask )的Activity 当遇到新的Intent的时候,

单顶模式(singleTop)

 intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);//原先已经存在这个即将跳到的Activity;

延伸---可以使用这个标志进行刷新Intent,进而刷新当前界面


不会走onCreate方法了,

而是走OnNewIntent方法,接着是生命周期其他方法;

<activity android:label="@string/app_name" android:launchmode="singleTask"android:name="Activity1"/>

所以在处理的是时候,OnNewIntent 的常用方法,是和OnCreate方法一样。

@Override
protected void onNewIntent(Intent intent) {
MyLog.d(TAG, TAG+"______ onNewIntent 0"+getIntent().getBooleanExtra(ComConstants.isAllowedSendVoiceMsg, isAllowedSendVoiceMsg));
MyLog.d(TAG, TAG+"______ onNewIntent 0-1"+intent.getBooleanExtra(ComConstants.isAllowedSendVoiceMsg, isAllowedSendVoiceMsg));
setIntent(intent);//注意  是设置的是intent  不是设置getIntent()
MyLog.d(TAG, TAG+"______ onNewIntent 1"+getIntent().getBooleanExtra(ComConstants.isAllowedSendVoiceMsg, isAllowedSendVoiceMsg));
super.onNewIntent(intent);
MyLog.d(TAG, TAG+"______ onNewIntent 2"+getIntent().getBooleanExtra(ComConstants.isAllowedSendVoiceMsg, isAllowedSendVoiceMsg));
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值