我正在使用解析推送通知我收到以下错误
Caused by: java.lang.IllegalStateException: ParsePlugins is already initialized
at com.parse.ParsePlugins.set(ParsePlugins.java:39)
at com.parse.ParsePlugins$Android.initialize(ParsePlugins.java:153)
at com.parse.Parse.initialize(Parse.java:358)
at com.parse.Parse.initialize(Parse.java:344)
at notifications.ParseUtils.registerParse(ParseUtils.java:30)
at com.techieweb.solutions.pickeronline.SplashActivity.onCreate(SplashActivity.java:24)
at android.app.Activity.performCreate(Activity.java:5326)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2218)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309)
at android.app.ActivityTh read.access$700(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
这是ParseUtils类
public class ParseUtils {
private static String TAG = ParseUtils.class.getSimpleName();
public static void verifyParseConfiguration(Context context) {
if (TextUtils.isEmpty(AppConfig.PARSE_APPLICATION_ID) || TextUtils.isEmpty(AppConfig.PARSE_CLIENT_KEY)) {
Toast.makeText(context, "Please configure your Parse Application ID and Client Key in AppConfig.java", Toast.LENGTH_LONG).show();
((Activity) context).finish();
}
}
public static void registerParse(Context context) {
// initializing parse library
Parse.initialize(context, AppConfig.PARSE_APPLICATION_ID, AppConfig.PARSE_CLIENT_KEY);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground(AppConfig.PARSE_CHANNEL, new SaveCallback() {
@Override
public void done(ParseException e) {
Log.e(TAG, "Successfully subscribed to Parse!");
}
});
}
public static void subscribeWithEmail(String email) {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("email", email);
installation.saveInBackground();
Log.e(TAG, "Subscribed with email: " + email);
}
}
我已将此用作参考http://www.androidhive.info/2015/06/android-push-notifications-using-parse-com/
这是MyApplication
public class MyApplication extends Application {
private static MyApplication mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
Parse.initialize(mInstance, AppConfig.PARSE_APPLICATION_ID, AppConfig.PARSE_CLIENT_KEY);
//register with parse
ParseUtils.registerParse(this);
}
public static synchronized MyApplication getInstance() {
return mInstance;
}
}
请帮忙。
答案 0 :(得分:1)
从oncCreate()
Parse.initialize(mInstance, AppConfig.PARSE_APPLICATION_ID, AppConfig.PARSE_CLIENT_KEY);
因为你已经在
中初始化了ParseUtils.registerParse(this);