I have an app on playstore and recently I have been getting these errors only on Android 8.0 devices. Please see the android stacktrace which I received from Google Play Console. I have also included the firebase helper classes. Thanks in advance :)
java.lang.IllegalStateException:
at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1737)
at android.app.ContextImpl.startService (ContextImpl.java:1693)
at android.content.ContextWrapper.startService (ContextWrapper.java:650)
at android.support.v4.content.WakefulBroadcastReceiver.startWakefulService (Unknown Source:22)
at com.google.firebase.iid.zzg.zzg (Unknown Source:9)
at com.google.firebase.iid.zzg.zzb (Unknown Source:78)
at com.google.firebase.iid.zzg.zzf (Unknown Source:2)
at com.google.firebase.iid.FirebaseInstanceIdService.a (Unknown Source:23)
at com.google.firebase.iid.FirebaseInstanceIdService.a (Unknown Source:34)
at com.google.firebase.iid.FirebaseInstanceId.<init> (Unknown Source:31)
at com.google.firebase.iid.FirebaseInstanceId.getInstance (Unknown Source:47)
at com.google.firebase.iid.FirebaseInstanceId.getInstance (Unknown Source:4)
at com.google.firebase.iid.FirebaseInstanceIdService.zza (Unknown Source:14)
at com.google.firebase.iid.FirebaseInstanceIdService.handleIntent (Unknown Source:35)
at com.google.firebase.iid.zzb$zza$1.run (Unknown Source:24)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
at java.lang.Thread.run (Thread.java:784)
MyFirebaseInstanceIdService class
public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService {
private static final String REG_TOKEN = "REG_TOKEN";
@Override
public void onTokenRefresh() {
String recent_token = FirebaseInstanceId.getInstance().getToken();
Log.d(REG_TOKEN, recent_token);
}
}
MyFirebaseMessagingService class
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent = new Intent(getApplicationContext(), OnlineActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notifcationBuilder = new NotificationCompat.Builder(getApplicationContext());
notifcationBuilder.setContentTitle("Dictionary Notification");
notifcationBuilder.setContentText(remoteMessage.getNotification().getBody());
notifcationBuilder.setAutoCancel(true);
notifcationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notifcationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.notify(0, notifcationBuilder.build());
}
}
}
Gradle file:
dependencies {
implementation 'com.android.support:support-vector-drawable:27.1.1'
implementation 'com.google.android.gms:play-services-plus:15.0.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.github.Hitomis:CircleMenu:v1.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.mindorks:placeholderview:0.2.7'
implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
}
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.github.amlcurran.showcaseview:library:5.4.3'
implementation 'com.pacioianu.david:ink-page-indicator:1.2.0'
implementation 'com.github.zcweng:switch-button:0.0.3@aar'
// Google
implementation 'com.google.android.gms:play-services-auth:15.0.1'
// Firebase
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.firebaseui:firebase-ui-database:1.2.0'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'de.hdodenhof:circleimageview:1.3.0'
implementation 'com.codemybrainsout.onboarding:onboarder:1.0.4'
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.huxq17.android:SwipeCardsView:1.3.5'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.airbnb.android:lottie:2.5.4'
}
apply plugin: 'com.google.gms.google-services'
This propably happens due to new background service restrictions introduced in Android 8 Oreo, see: https://developer.android.com/about/versions/oreo/android-8.0-changes#back-all
One suggested solution is to use JobScheduler (which I did), but this does not seem appropriate to a Firebase message receiver, so you might want to check the docs if there are some hints on this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With