0

Hi

I got an error message when i send a push message to my game in Android Oreo.
The game works well for all previous version of Android Oreo.
It only happens in Android Oreo.
I have searched many answers in this forum.
Some people say that i have to use FCM instead of GCM.
But I can't change my old Eclipse project to Android Studio because of many risks.
I use gcm.jar library.
Please help me & thanks in advance!

Logcat



        FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start receiver com.google.android.gcm.GCMBroadcastReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.example.test cmp=com.example.test/.GCMIntentService (has extras) }: app is in background uid UidRecord{7cd2325 u0a379 RCVR idle change:uncached procs:1 seq(0,0,0)}
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:3194)
        at android.app.ActivityThread.-wrap17(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1672)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)    
        Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.example.test cmp=com.example.test/.GCMIntentService (has extras) }: app is in background uid UidRecord{7cd2325 u0a379 RCVR idle change:uncached procs:1 seq(0,0,0)}
        at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1518)
        at android.app.ContextImpl.startService(ContextImpl.java:1474)
        at android.content.ContextWrapper.startService(ContextWrapper.java:649)
        at android.content.ContextWrapper.startService(ContextWrapper.java:649)
        at com.google.android.gcm.GCMBaseIntentService.runIntentInService(GCMBaseIntentService.java:282)
        at com.google.android.gcm.GCMBroadcastReceiver.onReceive(GCMBroadcastReceiver.java:55)
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:3187)


Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49
Ki Seok Kim
  • 19
  • 1
  • 1
  • *I have searched many answers in this forum.* - you didn't search very well. I just copied your error and found the exact same question – Tim Dec 11 '17 at 12:41
  • many people tell me to refer to the manual of 'backround execution limits'. or they say that i have to use 'startForegroundService' instead of 'startService'. but i can't understand what to do. i just use '' in AndroidManifest.xml file. and i use 'public class GCMIntentService extends GCMBaseIntentService { ... }'. that's all. it works well for all version of android except android oreo. please give me an example code. – Ki Seok Kim Dec 11 '17 at 13:09
  • @KiSeokKim Have you got the example ? – mob_web_dev Dec 25 '17 at 10:55

2 Answers2

3

Starting from Android O.

The startService() method now throws an IllegalStateException if an app targeting Android 8.0 tries to use that method in a situation when it isn't permitted to create background services.

By default, these restrictions only apply to apps that target O,but if user enable these restrictions for a particular app, then app will treated as same. For more info on topic read Background execution limits section here.

ADM
  • 20,406
  • 11
  • 52
  • 83
  • many people tell me to refer to the manual of 'backround execution limits'. or they say that i have to use 'startForegroundService' instead of 'startService'. but i can't understand what to do. i just use '' in AndroidManifest.xml file. and i use 'public class GCMIntentService extends GCMBaseIntentService { ... }'. that's all. it works well for all version of android except android oreo. please give me an example code. – Ki Seok Kim Dec 11 '17 at 13:11
  • @KiSeokKim have you got the solution ? – mob_web_dev Dec 26 '17 at 12:27
0

From API 26 onwords you won't be allow to start or destroy services in background.

https://developer.android.com/about/versions/oreo/background.html

for more detail read here.

There are so much limitations in API 26 for battery optimizations and some security reasons.

Harsh Patel
  • 1,056
  • 2
  • 10
  • 20
  • many people tell me to refer to the manual of 'backround execution limits'. or they say that i have to use 'startForegroundService' instead of 'startService'. but i can't understand what to do. i just use '' in AndroidManifest.xml file. and i use 'public class GCMIntentService extends GCMBaseIntentService { ... }'. that's all. it works well for all version of android except android oreo. please give me an example code. – Ki Seok Kim Dec 11 '17 at 13:11