关于活动的生命周期问题:onNewIntent /的onSaveInstanceState
-
27-09-2019 - |
题
我有ActivityLanding它调用称为ActivityFolder的活性。在意向我用putExtra( “folderId”, “...”)(我知道folderId是不是最好的例子)
我可以存储到一个变量,并使用它只是罚款,但如果最终我的活动就会被杀死,以节省内存我可能会失去folderId。当我的活动被再次推出,,将在 “额外”的意图GET保留吗?将在下面的工作精细的代码?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.folder);
onNewIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
String folderId = intent.getStringExtra("folderId"); // Might not be all digits
// load from server and fill in the blanks
}
如果它的不的获得保存,,然后可以用我改变的AsyncTask它,它仍然工作正常?
private class MyAsyncTask extends AsyncTask<String, Object, HashMap<String, Object>> {
.......................................
.......................................
.......................................
@Override
protected void onPostExecute(HashMap<String, Object> result) {
if (this.isCancelled())
return;
.....................
.....................
.....................
getIntent().putStringExtra("folderId", ""); // The server wants us to change what folder we are looking at
}
}
解决方案
在我的活动被再次推出,,将“额外”从意向获取保存?
是
不隶属于 StackOverflow