引起:java.lang.IllegalStateException:ParsePlugins 已经初始化 [英] Caused by: java.lang.IllegalStateException: ParsePlugins is already initialized

查看:23
本文介绍了引起:java.lang.IllegalStateException:ParsePlugins 已经初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我退出了应用程序,重新启动了它,但出现异常.

I quit the app, relaunch it, I am getting an exception.

public void onCreate() {
-->here Parse.initialize(this, "adfsfasdfs",
            "asdfadfsdf");
    ParseInstallation.getCurrentInstallation().saveInBackground();
    ParseInstallation.create(identity == null ? "No Identity Set"
            : identity);

异常

07-08 23:27:29.411: E/AndroidRuntime(4889): Caused by: java.lang.IllegalStateException: ParsePlugins is already initialized
07-08 23:27:29.411: E/AndroidRuntime(4889):     at com.parse.ParsePlugins.set(ParsePlugins.java:27)
07-08 23:27:29.411: E/AndroidRuntime(4889):     at com.parse.ParsePlugins.access$200(ParsePlugins.java:11)
07-08 23:27:29.411: E/AndroidRuntime(4889):     at com.parse.ParsePlugins$Android.initialize(ParsePlugins.java:141)
07-08 23:27:29.411: E/AndroidRuntime(4889):     at com.parse.Parse.initialize(Parse.java:178)
07-08 23:27:29.411: E/AndroidRuntime(4889):     at com.mcruiseon.caregiri.Registration.onCreate(Registration.java:98)

清单文件

        <service android:name="com.parse.PushService" />

        <receiver android:name="com.parse.ParseBroadcastReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.parse.ParsePushBroadcastReceiver"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>

我想知道为什么 Parse 会为此抛出异常.为什么不只是 info 并继续前进.它已初始化,如果我再次初始化它,那就太重要了.

I wonder why Parse would throw an exception for this. Why not just info and move on. Its initialized, so big deal if I initialized it again.

解决方案

我已经放弃了 Parse.不喜欢Application方式,就是烦维护.

I have given up on Parse. Dont like the Application way, just to irritating to maintain.

推荐答案

Parse.initialize() 应该在整个应用程序中调用一次.

Parse.initialize() should only be called once for an entire application.

ActivityonCreate 函数中调用它会导致它被多次初始化,因为 一个 Activity 可以在一个过程中被创建多次应用的生命周期.

Calling it in an Activity's onCreate function can cause it to be initialized more than once, as an Activity can be created more than once during an app's lifecycle.

相反,创建一个 Application 类(并将 android:name 属性添加到您的应用程序清单).

Instead, create an Application class (and add an android:name attribute to your your application's manifest).

应用:(注意不是活动/服务/接收者)

//Note that this is an android.app.Application class.
public class MyApplication extends android.app.Application {

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

    //This will only be called once in your app's entire lifecycle.
    Parse.initialize(this,
            getResources().getString(R.string.parse_application_id),
            getResources().getString(R.string.parse_client_key));
}

AndroidManifest:

<application
        android:name=".MyApplication">
        ....
        <activity>
            ....
        </activity>
</application>

这篇关于引起:java.lang.IllegalStateException:ParsePlugins 已经初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆