Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 如果使用推送服务关闭应用程序,应用程序崩溃:parse.com大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我将清单中的接收器替换为我的:

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

这是我的MyReceiver:

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,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清单中的应用程序标记,然后创建一个如下所示的新类:

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

以前我将Parse初始化调用放在我的主Activity的onCreate()方法中,但正如您发布的错误消息所示,Android生命周期的细微之处意味着您无法做到这一点.

大佬总结

以上是大佬教程为你收集整理的android – 如果使用推送服务关闭应用程序,应用程序崩溃:parse.com全部内容,希望文章能够帮你解决android – 如果使用推送服务关闭应用程序,应用程序崩溃:parse.com所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。