my app is force stopped by android Oreo battery optimisation, notifications are ignored afterward

1

Hello i'm having trouble with backgrounds limitations. The phone i am currently using for test is a Nokia 7 plus on Android 8.1

My app is running fine for a time, there is a jobScheduler which does a task every 20 minutes in background.

But at some point, to save the battery i believe that android shut down the app and afterward the broadcast receiver doesn't work as intended :

2019-02-28 10:13:25.925 3000-3000/? W/GCM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=myapp.pkg (has extras) }

When the app is on background and not force stopped, the message "broadcast intent callback: result=CANCELLED" is still displayed but the notification works.

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    Log.d(this.getClass().getName(),"Gcm Info Received");
    new Intent(context, GcmIntentService.class);
    GcmIntentService.enqueueWork(context, intent);
}

The log "Gcm Info Received" in my broadcast receiver is not even displaying while force stopped by battery.

Manifest

<receiver
        android:name=".GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="myapp.pkg" />
        </intent-filter>
    </receiver>

In my GcmIntentService, i add the following flag before sending the broadcast :

intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(intent);

The notifications messages are really important and i think it's really stupid that android automatically force stop apps. Only user interaction should be able to do it...

I saw this thread : https://github.com/firebase/quickstart-android/issues/89#issuecomment-233786785

And the Contributor speak like the "force stop" should be something the user do intentionally. In my case, the app has been running in background from 11am yesterday to 1am today before being stopped and not by me...

I also tried to test it from a signed apk version of the app as i saw someone said this error occurs when the app is in debbug only but it nothing changes.

I also read this thread : How to restart Service after Force Stop of app

So i would like to know if there is a real solutions to this and not asking every user to turn off the battery optimisation in settings ?

The solution could maybe be the app not being force killed by the battery optimization or somehow restart the app after a force kill.

java
android
broadcastreceiver
google-cloud-messaging
kill
asked on Stack Overflow Feb 28, 2019 by Maxime • edited Feb 28, 2019 by Maxime

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0