2017-10-12 51 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 
}