android.app.ContextImpl.startServiceCommon上的java.lang.IllegalStateException

时间:2018-07-21 02:27:58

标签: java android firebase android-studio

我在Playstore上有一个应用,最近我只在Android 8.0设备上遇到了这些错误。请查看我从Google Play控制台收到的android stacktrace。我还包括了Firebase助手类。在此先感谢:)

'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '1234';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Lang'] = '';

MyFirebaseInstanceIdService类

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) 

MyFirebaseMessagingService类

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);

    }
}

成绩文件:

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());
        }

    }
}

1 个答案:

答案 0 :(得分:0)

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

一个建议的解决方案是使用JobScheduler(我这样做了),但这似乎不适合Firebase邮件接收器,因此您可能需要检查文档,以了解是否有一些提示。