Sunday, 28 July 2019

Why backup related process might cause Application's onCreate is not executed?

It is common to have Application class as follow

public class WeNoteApplication extends MultiDexApplication {
    public static WeNoteApplication instance() {
        return me;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        me = this;


During normal circumstance, Application's onCreate will always be called before entry point Activity's onCreate.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Normally, it will NOT be null.
        android.util.Log.i("CHEOK", "WeNoteApplication -> " + WeNoteApplication.instance());

However, if I run the following command while the app is launched

c:\yocto>adb shell bmgr restore com.yocto.wenote
restoreStarting: 1 packages
onUpdate: 0 = com.yocto.wenote
restoreFinished: 0
done

The app will be closed. If, I tap on the app icon to launch again. This is what happens

  1. Application's onCreate is not executed!
  2. Activity's onCreate is executed, and WeNoteApplication.instance() is null

I look at some Google's Android source code (WorkManager for instance)

https://github.com/googlecodelabs/android-workmanager/issues/80

In their comment, they states that

// 1. The app is performing an auto-backup.  Prior to O, JobScheduler could erroneously
//    try to send commands to JobService in this state (b/32180780).  Since neither
//    Application#onCreate nor ContentProviders have run,...

It seems that, if backup related process is involved, Application's onCreate will not be executed!

May I know why it is so? Is this behavior ever documented some where?


Issue tracker

https://issuetracker.google.com/issues/138423608

Please kindly star the issue if you would like this issue to be resolved with higher priority.


Fully workable example for bug demostration

https://github.com/yccheok/AutoBackup-bug



from Why backup related process might cause Application's onCreate is not executed?

No comments:

Post a Comment