解析最终推送通知坠毁在android的背景 [英] Parse push notifications crashes eventually on background in android

查看:156
本文介绍了解析最终推送通知坠毁在android的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的解析来推Android通知,但它的背景最终崩溃,当我打开wifi关闭。

它给了我错误:

了java.lang.RuntimeException:无法启动接收com.parse.ParseBroadcastReceiver:了java.lang.RuntimeException:ApplicationContext就是空。使用解析库前必须先调用Parse.initialize(背景下,的applicationID,clientKey)。

这是我的code

 公共类ParseBroadcastReceiverCustom扩展广播接收器{@覆盖
公共无效的onReceive(最终上下文的背景下,意图意图){
    如果(意向== NULL)
        返回;
    ConnectionDetector连接=新ConnectionDetector(背景);    如果(connection.isNetworkAvailable()){
        PushService.startServiceIfRequired(上下文);
    }
}
}

和清单文件

 <接收
        机器人:名字=com.parse.ParsePushBroadcastReceiver
        机器人:出口=假>
        &所述;意图滤光器>
            <作用机器人:名字=com.parse.push.intent.RECEIVE/>
            <作用机器人:名字=com.parse.push.intent.DELETE/>
            <作用机器人:名字=com.parse.push.intent.OPEN/>
        &所述; /意图滤光器>
    < /接收器>

和主要活动onCreate方法

  ConnectionDetector连接=新ConnectionDetector(本);
    如果(connection.isNetworkAvailable()){
        PushService.setDefaultPushCallback(这一点,RegisterForget.class);
    }

任何帮助,请


解决方案

  1. PushService 是完全脱$ P $与新的API,你通过声明启用pcated的 ParsePushBroadcastReceiver 中你的清单。你可以阅读有关的变化在公告的博文推

  2. 您的答案是错误消息本身。呼叫Parse.initialze。您的活动的onCreate应该有
    Parse.initialize(这一点,你的申请ID,客户机密钥);
    如果你把这个code在活动,而不是你的应用程序,那么Android的可能您的应用程序停机由于不活动,然后通过推意图,而不是你的发射活动,在这种情况下,你会不会去拜访解析它重新启动.intialize。

I am using Parse to push notifications in android but it crashes eventually on background when i turn wifi off.

it gives me error:

java.lang.RuntimeException: Unable to start receiver com.parse.ParseBroadcastReceiver: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.

here is my code

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);
    }
}
}

and on manifest file

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

and on main activity onCreate method

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

any help please

解决方案

  1. PushService is complete deprecated with the new APIs, which you enabled by declaring the ParsePushBroadcastReceiver in your manifest. You can read about the changes to push in the announcement blogpost
  2. Your answer is in the error message itself. Call Parse.initialze. Your activity's onCreate should have Parse.initialize(this, "YOUR APPLICATION ID", "YOUR CLIENT KEY"); If you put this code in an activity rather than your application, then Android might shut down your app due to inactivity and then relaunch it via the push intent rather than your launcher activity, in which case you won't have called Parse.intialize.

这篇关于解析最终推送通知坠毁在android的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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