0

I want the app to start the main activity if and only if the app is not currently running. So, if the app is running, it just resumes; if not (closed/killed in order to get memory/etc), the main activity starts

The clearTaskOnLaunch flag is not the solution because it forcefully launches the main activity on click at the app icon, regardless of the current state, and because it does not affect launching the app from the Recent Apps menu - the last known state is always restored

Alex
  • 1,165
  • 2
  • 9
  • 27
  • This may be relevant http://stackoverflow.com/questions/19545889/app-restarts-rather-than-resumes – cyroxis Aug 20 '15 at 12:05
  • The goal is *not* to resume to the last screen shown after the app gets killed – Alex Aug 20 '15 at 12:06
  • 1
    If the app is killed how is it going to resume the last activity? There is no longer any 'last activity' state in memory. – cyroxis Aug 20 '15 at 12:07
  • Well, the situation: I launch the app, go to the settings screen and then switch to web browser. In order to get more memory, the system (partly) kills the app leaving the information about the last app state. When I switch back to the app, the settings activity is restored, but the rest of the app is down according to the `NPE` thrown at the attempt to get data from the other activity – Alex Aug 20 '15 at 12:33

1 Answers1

0

A solution quite similar to one in the post suggested by cyroxis seems to work: added a piece of code to check sharedPreferences != null condition in onCreate():

if (sharedPreferences == null) {
    finish();
    return;
}
Alex
  • 1,165
  • 2
  • 9
  • 27