Android启动停止后台服务+ oreo 8.0 [英] Android start stop background service + oreo 8.0

查看:405
本文介绍了Android启动停止后台服务+ oreo 8.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我们在oreo 8.0启动和停止后台服务时遇到问题



错误:

FATAL EXCEPTION:main

进程:com.phonov1.app,PID:4121

android.app.RemoteServiceException:Context.startForegroundService()之后没有调用Service。在Android.app.Handler.dispatchMessage(Handler.java:106 )

在android.os.Looper.loop(Looper.java:164)

在android.app.ActivityThread.main(ActivityThread.java:6626)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438)

在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)





我尝试了什么:



我有试图开始服务

Intent in = new Intent(this,GpsService.class);

startService(in); //适用于8.0以下的Android版本



startForegroundService(中)//适用于Android版本8.0



和我试图停止服务



stopService(new Intent(this,GpsService.class));

Hello,
We are facing issue while start and stop background service in oreo 8.0

Error :
FATAL EXCEPTION: main
Process: com.phonov1.app, PID: 4121
android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
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:811)


What I have tried:

I have tried to start service
Intent in = new Intent(this,GpsService.class);
startService(in); // for android version below 8.0

startForegroundService(in) //for android version 8.0

and I have tried to stop service by

stopService(new Intent(this,GpsService.class));

推荐答案

H.handleMessage(ActivityThread.java:1821)

在android.os.Handler.dispatchMessage(Handler.java:106)

在android.os.Looper .loop(Looper.java:164)

在android.app.ActivityThread.main(ActivityThread.java:6626)

在java.lang.reflect.Method.invoke (原生方法)

在com.android.internal.os.RuntimeInit
H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit


MethodAndArgsCaller.run(RuntimeInit.java:438)

在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)





我尝试了什么:



我试图开始服务

意图=新意图(这个,GP sService.class);

startService(in); //适用于8.0以下的Android版本



startForegroundService(中)//适用于Android版本8.0



和我试图停止服务



stopService(new Intent(this,GpsService.class));
MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)


What I have tried:

I have tried to start service
Intent in = new Intent(this,GpsService.class);
startService(in); // for android version below 8.0

startForegroundService(in) //for android version 8.0

and I have tried to stop service by

stopService(new Intent(this,GpsService.class));


这篇关于Android启动停止后台服务+ oreo 8.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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