I have ActivityLanding which calls an activity called ActivityFolder. In the intent I used putExtra("folderId", "...") (I know folderId is not the best example)
I can store that to a variable and use it just fine but if eventually my activity gets killed to save memory I may lose the folderId. When my activity gets launched again,, will the "extras" from the intent get preserved? Will the code below work fine?
@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
}
If it does get preserved,, then can I change it using ASyncTask and it still work fine?
private class MyAsyncTask extends AsyncTask<String, Object, HashMap<String, Object>> {
.......................................
.......................................
.......................................
@Override
protected void onPostExecute(HashMap<String, Object> result) {
if (this.isCancelled())
return;
..........开发者_JS百科...........
.....................
.....................
getIntent().putStringExtra("folderId", ""); // The server wants us to change what folder we are looking at
}
}
When my activity gets launched again,, will the "extras" from the intent get preserved?
Yes.
精彩评论