簡體   English   中英

永不調用onRestoreInstanceState,/ saveInstanceState始終為null

[英]onRestoreInstanceState is never called / savedInstanceState is always null

我瀏覽了所有站點,但我不明白為什么它對我不起作用。

請找到我的源代碼:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        Log.e("EVERYTHING", "OK");
    }
}

@Override
public void onSaveInstanceState(Bundle outState) {
    outState.putString("test", "titi");
    Log.e("Save", "titi");
    super.onSaveInstanceState(outState);
}

我啟動我的應用程序,然后按主頁按鈕,然后重新啟動手機並再次啟動該應用程序,但savedInstanceState為null。

請你幫助我好嗎。 問候

onSaveInstanceState用於將狀態保留在內存中,因此不適用於上述情況。 如果重新啟動手機,顯然不會永久保留所有狀態存儲(僅在內存中)。

如果要以這種方式存儲狀態,則應查看一些持久性內容,例如共享首選項或SQLite。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM