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:

  1. when activity gets restored, check if data in application object null
  2. 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

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -