2017-10-12 55 views
0

我在清单文件中宣布我的活动为singleTop。 当我启动此活动时,我正在传递一些有意义的值。我做的重启活动Android singleTop活动问题

Intent i= new Intent(A.this,MysingleTopActivity.class); 
i.putExtra("isActive",true); 
startActivity(i); 

相同的步骤,从B级

Intent i= new Intent(B.this,MysingleTopActivity.class); 
i.putExtra("isActive",false); 
startActivity(i); 

所以这个我在MysingleTopActivity的onNewIntent()方法得到调用。与isActive =false

但如果我旋转屏幕然后onCreate()将调用,并在“isActive =真”。

我该如何检索该活动的当前实例值?

感谢

+1

你有没有在onNewIntent setIntent? – Selvin

+2

@Parth你需要在onNewIntent()方法中设置意图,以便下次获得更新的意图 – nomag

+0

不,我没有在onNewIntent()方法中设置意图。我尝试了它的工作意图。非常感谢。 – Parth

回答

0

为了实现这个结果需要在onNewIntent(Intent newintent) {} methold添加

setIntent(newintent); 

屏等newintent的旋转将在交付的onCreate();

示例代码:

@Override 
    protected void onNewIntent(Intent intent) { 
     super.onNewIntent(intent); 
     setIntent(intent); 
//add your code 
}