gpt4 book ai didi

android - 如果使用推送服务 : parse. com 关闭应用程序,应用程序会崩溃

转载 作者:太空宇宙 更新时间:2023-11-03 12:18:11 25 4
gpt4 key购买 nike

我将 list 中的接收器替换为我的:

<receiver android:name="com.myparse.app.MyReceiver"
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>

这是我的接收者:

public class MyReceiver extends ParsePushBroadcastReceiver {

@Override
protected void onPushReceive(Context mContext, Intent intent) {
// super.onPushReceive(arg0, arg1);

if (intent.hasExtra("com.parse.Data")){
String jsonString=intent.getExtras().getString("com.parse.Data");
//-------------
}

public void onPushOpen(Context context, Intent intent) {

//To track "App Opens"
ParseAnalytics.trackAppOpenedInBackground(intent);

//Here is data you sent
Log.i("", intent.getExtras().getString( "com.parse.Data" ));

Intent i = new Intent(context, MainActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}

一切正常但是如果我关闭应用程序,然后发送推送通知-> 应用程序崩溃并显示以下日志:

11-09 21:13:11.621: E/com.parse.PushService(23087): The Parse push service cannot start because Parse.initialize has not yet been called. If you call Parse.initialize from an Activity's onCreate, that call should instead be in the Application.onCreate. Be sure your Application class is registered in your AndroidManifest.xml with the android:name property of your <application> tag.
11-09 21:13:11.626: E/AndroidRuntime(23087): FATAL EXCEPTION: main
11-09 21:13:11.626: E/AndroidRuntime(23087): java.lang.RuntimeException: Unable to start service com.parse.PushService@4203adb0 with Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10 pkg=com.myparse.app cmp=com.myparse.app/com.parse.PushService (has extras) }: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
11-09 21:13:11.626: E/AndroidRuntime(23087): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2782)
11-09 21:13:11.626: E/AndroidRuntime(23087): at dalvik.system.NativeStart.main(Native Method)
11-09 21:13:11.626: E/AndroidRuntime(23087): Caused by: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
11-09 21:13:11.626: E/AndroidRuntime(23087): at com.parse.Parse.checkContext(Parse.java:606)

最佳答案

我遇到了同样的问题,通过添加解决了android:name=".MyApplication" 添加到 Android list 中的应用程序标签,然后创建一个如下所示的新类:

public class MyApplication extends Application 
{
@Override
public void onCreate() {
Parse.initialize(getApplicationContext(), myAppId, myClientKey);
}
}

以前我将 Parse 初始化调用放在我的主 Activity 的 onCreate() 方法中,但正如您发布的错误消息所暗示的那样,Android 生命周期的微妙之处意味着您不能这样做。

关于android - 如果使用推送服务 : parse. com 关闭应用程序,应用程序会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26831663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com