When passed to a child activity, the Bundle becomes null
I’m using the standard Android Intent/Bundle method to pass data to child activities.
The problem is that while intents look good before the activity starts, they appear null in child activities. I can’t find anyone else who has encountered this issue, so I thought I’d ask for instructions on where to look/how to debug.
(Target Android 2.1).
Parent Activity Fragment
:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(ctx, ArticleView.class);
i.putExtra("url", articles.get(position).url.toString());
The following line correctly logs the URL
Log.d(TAG,"Starting article viewer with url " + i.getStringExtra("url"));
startActivityForResult(i,ACTIVITY_ARTICLE);
}
child Activity fragment :
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.article_view);
if (icicle != null) {
Never called!
} else {
Always called
Log.d(TAG,"Icicle is null - no URL passed in");
}
}
Ignoring the fact that icicle is null and trying to retrieve state information from it (using getString) results in a hang and:
03-14 22:23:03.529: WARN/ActivityManager(52): Activity HistoryRecord{44ddd238 com.t.s/. ArticlesList} being finished, but not in LRU list
Any tips are greatly appreciated.
Solution
What is passed to the child activity (or any activity) constructor is not an intent.
Intent can be obtained by
acquiring
Intent intent = getIntent();
The bundle icicle you are referring to is the bundle that an activity uses when it resumes from a suspended state. For example. If you need to save any state of an activity before restarting, this is where the data is stored.