android - 解析推送通知最终在 Android 后台崩溃

标签 android parse-platform push-notification

我正在使用 Parse 在 Android 中推送通知,但当我关闭 wifi 时,它最终会在后台崩溃。

它给了我错误:

java.lang.RuntimeException:无法启动接收器 com.parse.ParseBroadcastReceiver:java.lang.RuntimeException:applicationContext 为 null。在使用Parse库之前,您必须调用Parse.initialize(context, applicationId, clientKey)。

这是我的代码

public class ParseBroadcastReceiverCustom extends BroadcastReceiver {

@Override
public void onReceive(final Context context, Intent intent) {
    if(intent == null)
        return;
    ConnectionDetector connection = new ConnectionDetector(context);

    if (connection.isNetworkAvailable()) {
        PushService.startServiceIfRequired(context);
    }
}
}

以及 list 文件

 <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>

以及主要 Activity 的 onCreate 方法

    ConnectionDetector connection = new ConnectionDetector(this);
    if (connection.isNetworkAvailable()) {
        PushService.setDefaultPushCallback(this, RegisterForget.class);
    }

请帮忙

最佳答案

    新 API 已完全弃用
  1. PushService,您可以通过在 list 中声明 ParsePushBroadcastReceiver 来启用新 API。您可以在announcement blogpost中阅读有关推送的更改
  2. 您的答案就在错误消息本身中。调用 Parse.initialze。你的 Activity 的 onCreate 应该有 Parse.initialize(this, "您的应用程序 ID", "您的客户端 key "); 如果您将此代码放入 Activity 而不是您的应用程序中,那么 Android 可能会因不活动而关闭您的应用程序,然后通过推送 Intent 而不是您的启动器 Activity 重新启动它,在这种情况下您将不会调用 Parse.intialize。

关于android - 解析推送通知最终在 Android 后台崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27506543/

相关文章:

android - LinearLayout 中的 fill_parent 没有得到尊重

未收到在 Back4App 上使用 Parse 的 Android 推送通知

ios - 解析 Objective C 库在 [PFInternalUtils installationId] 上崩溃

rest - 解析(解析服务器): Code 111 Schema mismatch when trying to add Relation using REST API

ios - 如何保存NSMutableArray来解析?

android - 静态 Activity 生成器?

android - Apache Cordova 错误的 Visual Studio 工具

android - 我现在应该使用什么方法,因为 FirebaseInstanceId.getInstance().getToken() 已被弃用

flutter - 服务器发送请求后运行功能的最佳方法是什么?

php - PubNub 推送通知