custom android.app.Application not firing onCreate event

前端 未结 6 589
粉色の甜心
粉色の甜心 2021-01-01 09:31

I\'m deriving a custom application from android.app.Application and I can\'t get its onCreate event being fired. Here\'s the implementation

import android.ap         


        
6条回答
  •  甜味超标
    2021-01-01 10:03

    You don't actually create instances of your Activities with the newoperator. Instead you start an Intent like this:

    Intent start = new Intent(context, Classname.class);
    context.startActivity(start);
    

    When creating an object with the new operator, then onCreate never will be called.

    [EDIT] When creating Applications with the new operator onCreate won't be called either[/EDIT]

    [EDIT2] You could create a static method that returns the application like this:

    public static MyApplication getApp() {
        return mInstance;
    }
    

    [/EDIT2]

提交回复
热议问题