当Activity launchMode为singleTask或singleInstance,启动一个activity时通过intent.putExtra传数据时,在该Activity中通过getIntent() 获取的intent对象获取Extra参数为空,只有第一次获取到的对象不为空。
原因是:activity的getIntent()方法只是获取activity原来的intent。
解决方法:重载onNewIntent()方法。
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); //通过 intent获取传递过来的数据 if(intent != null && intent.getBooleanExtra("srartRecordScreen",false)){ Log.d(TAG, "onNewIntent startCountTime"); startCountTime(); } }