相关疑难解决方法(0)

然后Context.startForegroundService()没有调用Service.startForeground()

Service在Android O OS上使用Class.

我计划Service在后台使用.

Android建议指出startService()应该使用startForegroundService().

如果您使用startForegroundService(),则Service抛出a Service然后调用Service错误.

这有什么问题?

service android operating-system foreground android-8.0-oreo

212
推荐指数
18
解决办法
11万
查看次数

RemoteServiceException: Context.startForegroundService 然后没有调用 Service.startForeground

我从以下异常输出Device Monitor

//FATAL EXCEPTION: main
//Process: com.xxx.yyy, PID: 11584
//android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()
//    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1881)
//    at android.os.Handler.dispatchMessage(Handler.java:105)
//    at android.os.Looper.loop(Looper.java:164)
//    at android.app.ActivityThread.main(ActivityThread.java:6944)
//    at java.lang.reflect.Method.invoke(Native Method)
//    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
//    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Run Code Online (Sandbox Code Playgroud)

我的应用程序中有 4 个服务,它们基本上都是这样的:

public class MyService extends Service {

    private static final int forgroundId = 55544433; //Unique for each Service
    private Notification notification;

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) { …
Run Code Online (Sandbox Code Playgroud)

service android android-notifications foregroundnotification

4
推荐指数
1
解决办法
2111
查看次数