Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Application not created on Android M (final preview)

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.


Code example

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>

Logcat output

The screenshot below shows the Logcat output after launching the app from a clean install, and then launching it again 8 seconds after.

Logcat output

like image 640
Michell Bak Avatar asked Aug 18 '15 08:08

Michell Bak


1 Answers

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

like image 130
Michell Bak Avatar answered Nov 12 '22 01:11

Michell Bak