The documentation of Application#onCreate()
states:
Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created.
This has been true in practise for as long as I can remember and a lot of applications rely on this for initializing various stuff. However, this behavior has seemingly changed with the latest Android M preview (released yesterday).
When the application is first installed and launched, the custom Application
's onCreate()
won't be called. Instead, it'll launch the first Activity
immediately.
This only happens on the very first application start. All following application starts work and behave as expected and the custom Application
's onCreate()
is called before starting the Activity
.
BaseApplication
public class BaseApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Log.d("App", "Test: Application.onCreate()");
}
}
FirstActivity
public class FirstActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("App", "Test: Activity.onCreate()");
}
}
App manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.package.name" >
<application android:name=".application.BaseApplication" >
[...]
</application>
</manifest>
The screenshot below shows the Logcat output after launching the app from a clean install, and then launching it again 8 seconds after.
This has been fixed in the final release of Android 6.0, as per the official issue tracker: https://code.google.com/p/android-developer-preview/issues/detail?id=2965
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With