android - Clear back stack when application object gets killed by the system -
i have application lot of activities. among them there initialactivity
loads core data. it's launcher activity , none of next activities can live without loaded data.
so launch app, initialactivity
loading data, navigates mainactivity
, i'm browsing farawayactivity
. i'm switching other apps (some of them heavy games) , application getting killed on background. i've inserted log call in application.oncreate()
, can see it's called again, when switch application. i'm sure app killed on background. android brings last farawayactivity
top , crashes because loaded data nulls.
so question is: how can tell application start on initialactivity
when (and when) it's getting killed , restored? "forget stack", presumably automatically, in manifest.
i've read , tried activity tag docs, nothing matches expectations. closest thing android:cleartaskonlaunch="true"
, clears other activities on stack when relaunching app desktop (and app isn't killed yet, data available). clear, want start initialactivity after app killed.
first suggest instead of storing in application, pass data activity through intent. way when activity restored, saved intent bring data back.
now suggestion actual question:
- when activity gets restored, check if data in application object null
if should call this:
intent newintent = new intent(farawayactivity.this, initialactivity.class); newintent.addflags(intent.flag_activity_clear_top); newintent.addflags(intent.flag_activity_new_task); startactivity(newintent);
now should clear stack till find initialactivity.
Comments
Post a Comment