Parse.com runtime crash - android

I get a lot of messages from users about the failure of my application. The persistent error seems to be related to my initialization of parse.com, however I configured it as described in the parsing guide.

here is the stack trace:

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. at android.app.ActivityThread.handleReceiver(ActivityThread.java:2580) at android.app.ActivityThread.access$1700(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5292) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library. at com.parse.Parse.checkContext(Parse.java:606) at com.parse.Parse.getApplicationContext(Parse.java:214) at com.parse.ManifestInfo.getContext(ManifestInfo.java:322) at com.parse.ManifestInfo.getPackageManager(ManifestInfo.java:330) at com.parse.ManifestInfo.getPackageInfo(ManifestInfo.java:356) at com.parse.ManifestInfo.deviceSupportsGcm(ManifestInfo.java:441) at com.parse.ManifestInfo.getPushType(ManifestInfo.java:210) at com.parse.PushService.startServiceIfRequired(PushService.java:168) at com.parse.ParseBroadcastReceiver.onReceive(ParseBroadcastReceiver.java:19) at android.app.ActivityThread.handleReceiver(ActivityThread.java:2573) ... 10 more 

and here is my initialization code:

 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home_screen); Parse.initialize(this, "hGG5RdgNVdI7eCeZynV32lWYXywQRHkpp5zLdY7Q", "TwmNbpBYEt4u3euE3lzNIgwyroSl8RPGF2dJFsPv"); ParseInstallation.getCurrentInstallation().saveInBackground(); 

Can anyone understand what causes this error, and how to fix it?

below is the code of my receiver:

 public static class Receiver extends ParsePushBroadcastReceiver { private String notificationText; private Boolean notificationreceived = false; public Receiver(){ } private static final String TAG = "MyNotificationsReceiver"; @Override public void onPushOpen(Context context, Intent intent) { Log.e("Push", "Clicked"); Intent i = new Intent(context, HomeScreen.class); notificationreceived = true; i.putExtra("alert",notificationText); i.putExtra("alertreceived", notificationreceived); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); Scb998.scb988b=true; try { JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data")); Scb998.msg = json.getString("alert"); } catch (JSONException e) { Log.d(TAG, "JSONException: " + e.getMessage()); } } } 
+5
source share
1 answer

You move the Parse initialization to your App class (extended from Application )

 public class App extends Application { @Override public void onCreate() { super.onCreate(); Parse.initialize(this, "hGG5RdgNVdI7eCeZynV32lWYXywQRHkpp5zLdY7Q", "TwmNbpBYEt4u3euE3lzNIgwyroSl8RPGF2dJFsPv"); ParseInstallation.getCurrentInstallation().saveInBackground(); } } 

And of course, refer to it AndroidManifest.xml

 <application android:name=".app.App" .... </application> 

The cause of the accident is as follows. When your application is in the background, it can be killed by the system. From the Google manual

A process containing an activity that is currently not visible to the user (the onStop () method was called). These processes do not directly affect the user interface, and the system can kill them at any time in order to restore memory for the foreground, visible or service process. Usually many background processes run, so they are stored in the LRU list (the least recently used) to ensure that a process with activity that was recently noticed by the user is the last to be killed. If an action correctly implements its life cycle methods and saves its current state, its process will not have a noticeable effect on the user interface, because when a user switches to activity, activity restores all of his visible state. For information on saving and restoring the state, see the "Actions" document.

When the application receives a push notification, the parsing will not be initialized because you initialize it using the onCreate method, which will not be called.

+9
source

Source: https://habr.com/ru/post/1209410/


All Articles