android.app.ContextImpl.startServiceCommon 处的 java.lang.IllegalStateException [英] java.lang.IllegalStateException at android.app.ContextImpl.startServiceCommon

查看:18
本文介绍了android.app.ContextImpl.startServiceCommon 处的 java.lang.IllegalStateException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Playstore 上有一个应用程序,最近我只在 Android 8.0 设备上遇到这些错误.请查看我从 Google Play Console 收到的 android 堆栈跟踪.我还包括了 firebase 助手类.提前致谢:)

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 类

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 类

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 文件:

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'

推荐答案

这可能是由于 Android 8 Oreo 中引入的新后台服务限制导致的,请参阅:https://developer.android.com/about/版本/oreo/android-8.0-changes#back-all

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

一个建议的解决方案是使用 JobScheduler(我这样做了),但这似乎不适用于 Firebase 消息接收器,因此如果有一些提示,您可能需要查看文档.

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.

这篇关于android.app.ContextImpl.startServiceCommon 处的 java.lang.IllegalStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆