How to know when Parse.initialize() has already been called?

后端 未结 2 755
挽巷
挽巷 2021-01-02 10:00

Right now I am using a static boolean to tell when the initialization has occurred. Is there an easier way to know that I have already called initialize?

Thank you!!

相关标签:
2条回答
  • 2021-01-02 10:15

    Make a Application Class and in onCreate initialize parse.

    public class YourApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Parse.initialize(this, "id","key");
        }
    }
    

    After this it wont be called again and again.

    Also declare it in your manifest

    <application
        android:name="com.you.yourapp.YourApplication "
    

    EDIT: This is the only place where you initialize it. And not in the Login Activity or anywhere else.

    0 讨论(0)
  • 2021-01-02 10:24

    If you, like me, for some reason can not use custom Application class, just surround the init method with try/catch, like this:

    private void initParse() {
        try {
            Parse.initialize(getApplication(), "some id here", "another id here");
            ParseInstallation.getCurrentInstallation().saveInBackground();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    That way it won't crash the whole app, and the SDK will still work, tested it.

    0 讨论(0)
提交回复
热议问题