Myat Min Soe
Myat Min Soe

Reputation: 807

App crashes on parse push notification when the app is not running

When I open my android app and test parse push notification, it works. But when I killed my app from multitasking and test again, app crashes.

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Parse.initialize(MainActivity.this, "cMm2mJvkRlIButQ0wM4lfj5veFxrQYUKw8P4mdM4", "bOplHPHvWb9IRzv2EbQnylWFgyveTsDYEspV2qs0");
        ParseAnalytics.trackAppOpenedInBackground(getIntent());
        ParsePush.subscribeInBackground("", new SaveCallback() {
            @Override
            public void done(ParseException e) {
                if (e == null) {
                    Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
                } else {
                    Log.e("com.parse.push", "failed to subscribe for push", e);
                }
            }
        });
}

Error Log

08-18 21:16:21.694 24406-24406/? E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.myatminsoe.mkeyboard, PID: 24406 java.lang.RuntimeException: Unable to create service com.parse.PushService: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.parse.ParsePlugins$Android.applicationContext()' on a null object reference at android.app.ActivityThread.handleCreateService(ActivityThread.java:2771) at android.app.ActivityThread.access$1800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1386) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.parse.ParsePlugins$Android.applicationContext()' on a null object reference at com.parse.PushService.onCreate(PushService.java:238) at android.app.ActivityThread.handleCreateService(ActivityThread.java:2761)             at android.app.ActivityThread.access$1800(ActivityThread.java:151)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1386)             at android.os.Handler.dispatchMessage(Handler.java:102)             at android.os.Looper.loop(Looper.java:135)             at android.app.ActivityThread.main(ActivityThread.java:5254)             at java.lang.reflect.Method.invoke(Native Method)             at java.lang.reflect.Method.invoke(Method.java:372)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Upvotes: 2

Views: 1082

Answers (1)

1'hafs
1'hafs

Reputation: 579

Do the parse initialisation in Application onCreate and make sure you are calling it in the mainThread.

Parse.initialize(new Parse.Configuration.Builder(getApplicationContext()).applicationId(
                    ...).build());

Upvotes: 3

Related Questions