When starting the application a second time, the onCreate application class is not called. First time around. This can be reproduced using Android Studio to create a new application, and then adding the minimum Singleton application class:
package com.whatever.test;
import android.app.Application;
import android.content.Context;
import android.util.Log;
public class MyApp extends Application {
private static MyApp singleton;
public static MyApp getInstance(Context context) {
Log.i("MyApp","---------->getinstance");
return singleton;
}
@Override
public void onCreate()
{
super.onCreate();
singleton = this;
Log.i("MyApp","---------->act oncreate");
}
}
and in adding activity in onCreate:
MyApp myApp = MyApp.getInstance(this);
Log.i("MainActivity", "-------->onCreate");
and in onDestroy:
@Override
public void onDestroy()
{
super.onDestroy();
Log.i("MainActivity", "-->onDestroy");
}
Manifest.xml contains:
android:name=".MyApp"
I press the back button in action and see the onDestroy call being called, but this is apparently not enough to remove the Application class. If I kill the application using the phone’s application manager and run it again, I’ll see the App onCreate log again (but in just one run).
? . , , , , , .
. (Galaxy S3).