Application singleton use in Android

前端 未结 3 1339
暖寄归人
暖寄归人 2020-12-21 03:03

I have a facebook initialize sdk call and I need it to initialize the moment application is launched:

I want to use my Application class to do that. for example:

3条回答
  •  醉梦人生
    2020-12-21 03:37

    When you extend android.app.Application class, you do not have to call onCreate explicitly. But make sure you specify it in AndroidManifest.xml, like this android:name="fully-qualified name" eg: android:name="com.example.MyApplication"

    You don't have to implement Singleton pattern cause Application IS ALREADY A SINGLETON, there is only one instance of your Application. And, to get the instance of Application or the any custom child of Application you defined, you can simply call context.getApplication().

    Reference https://developer.android.com/reference/android/app/Application.html

提交回复
热议问题