2

I am using android.app.Application to create a single instance. For some reason I see Android kills my Instance and recreate (call onCreate). How can I stop this from happening ? I tried adding logs on onTerminate and onLowMemory but non of these get called before Instance get killed.

Please advice.

public class Instance extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
  }

  @Override
    public void onTerminate() {
        super.onTerminate();
        Log.e(TAG, "onTerminate");
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
            Log.e(TAG, "onLowMemory");
    }
}
user1546570
  • 287
  • 3
  • 13

1 Answers1

2

For some reason I see Android kills my Instance and recreate (call onCreate)

That is fully expected behavior in Android OS. If you need smth to track some app's state, then you need to use some persistance means: file storage, shared preferences or ContentProvider. More details on this here: https://stackoverflow.com/a/4642069/247013

Community
  • 1
  • 1
Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91