您好我安装了Parse推送通知。当我尝试打开我的应用时,我的应用正在关闭。
logcat的
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.goksuahmet.mekim/com.goksuahmet.mekim.splash}: java.lang.IllegalStateException: ParsePlugins is already initialized
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3930)
at android.app.ActivityThread.access$900(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1327)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
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:378)
at com.parse.Parse.initialize(Parse.java:331)
at com.goksuahmet.mekim.splash.onCreate(splash.java:16)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3930)
at android.app.ActivityThread.access$900(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1327)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
我的清单 我从parse的网站上编写代码。
<?xml version="1.0" encoding="utf-8"?>
-
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.goksuahmet.mekim.permission.C2D_MESSAGE" />
<uses-permission android:name="com.goksuahmet.mekim.permission.C2D_MESSAGE" />
<supports-screens
android:largeScreens="true"
android:xlargeScreens="true" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="oKsO63AavckYOzVOiwpUgUBEQhaGECkWiJLV6qti" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="GoAN842J1l6WlQBUYFXl6AitgO1GFKB93BmU7Oc8" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDM27rYpQ4wKwaFFyWU_CvJUHjaHdML-tg" />
<activity android:name=".splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Main"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity
android:name=".neredeyiz"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity
android:name=".mekim_nasil"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<service android:name="com.parse.PushService" />
<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>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.goksuahmet.mekim" />
</intent-filter>
</receiver>
</application>
我的java 我打电话来解析
@Override
public void onCreate(Bundle savedInstanceState) {
Parse.initialize(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);}
为什么关闭我的应用?我该如何解决?感谢..
答案 0 :(得分:1)
您之前的某些Parse.initialize()
可能会调用Activity
。应用程序生命周期中只应调用此方法一次。而是创建一个Application
类,并在其Parse.initialize()
方法中添加onCreate
。所以做这样的事情:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, getResources().getString(R.string.parse_app_id), getResources().getString(R.string.parse_client_key));
}
在您创建MyApplication
课程后,您需要将其作为属性(android:name=".MyApplication"
)添加到您的应用清单中。这就是你的清单应该是这样的:
<?xml version="1.0" encoding="utf-8"?>
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.goksuahmet.mekim.permission.C2D_MESSAGE" />
<uses-permission android:name="com.goksuahmet.mekim.permission.C2D_MESSAGE" />
<supports-screens
android:largeScreens="true"
android:xlargeScreens="true" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/icon"
android:label="@string/app_name"
android:name=".MyApplication"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="oKsO63AavckYOzVOiwpUgUBEQhaGECkWiJLV6qti" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="GoAN842J1l6WlQBUYFXl6AitgO1GFKB93BmU7Oc8" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDM27rYpQ4wKwaFFyWU_CvJUHjaHdML-tg" />
<activity android:name=".splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Main"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity
android:name=".neredeyiz"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity
android:name=".mekim_nasil"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<service android:name="com.parse.PushService" />
<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>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.goksuahmet.mekim" />
</intent-filter>
</receiver>
</application>