ParseBroadcastReceiver on Android causes my application to crash when the device is rebooted

165 Views Asked by At

I have an Android application that is using Parse. Generally everything works as expected. I have followed all the instructions and tutorials and all is well with my application. I receive notifications and my app handles them well.

The only issue I am seeing is that when my Galaxy S6 running the application is restarted I get the start "Application has stopped".

Now, at this point, my application isn't even running. I was able to narrow down the issue to the ParseBroadcastReceiver:

     <receiver android:name="com.parse.ParseBroadcastReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>

This makes sense as this receiver has an intent filter for BOOT_COMPLETED, which means this receiver runs when the device is booted. Commenting out this receiver eliminates the problem.

Has anyone seen or solved this problem?

1

There are 1 best solutions below

2
On

sorry for my english but i will do my best helping you.

You have to create a new class which extends Application, without layout, just a java class.

My class looks like this:

public class Init extends Application {

@Override
public void onCreate() {
    super.onCreate();
    Parse.initialize(this, "applicationID", "clientKey");
    ParseInstallation.getCurrentInstallation().saveInBackground();

}

And you have to declare on your manifest like:

 <application
    android:name="your_package.class_which_initialize_service">
  <!--All your things of your manifest here-->
 </application>

As child of manifest root. (Many times just adding

android:name="your_package.class_which_initialize_service"

is enough

I hope that this help you and sorry again for my bad english :P

EDIT: Yes, commenting this line fix the problem but the services won't initializes automatically. Just launching your app manually. I forgot to say that the sentence which initialize service cannot be duplicated, you have to delete this line from the class before, and copy to the class I wrote