当应用程序仅在华为设备中关闭时,服务被终止 [英] service killed when app cloes just in huawei device
问题描述
我总是向Toast发送文本服务,但只是在我杀死应用程序时就在huawei设备服务中被杀死.
我不知道为什么?
I make service to Toast a text always but just in huawei device service killed when i kill app.
I don't know why?
我的服务是:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
onTaskRemoved(intent);
new CountDownTimer(99999999L,5000 ) {
@Override
public void onTick(long arg0) {
Toast.makeText(getApplicationContext(), "hihihi", Toast.LENGTH_LONG).show();
}
@Override
public void onFinish() {
}
}.start();
return START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
推荐答案
一个古老的问题,但我认为了解HUAWEI具有一项称为耗电量大的应用程序监控器"的功能非常重要.
An old question, but I think it’s important to know that HUAWEI has a feature called "power-intensive app monitor".
除非用户授予特殊权限,否则它将杀死长时间在后台运行的每个应用程序.
It kills every app that runs in the background for a long time unless user gives special permissions to it.
执行此操作的路径:设置->安全性和隐私->位置服务->最近的位置请求:您的应用名称->电池->取消选中耗电量大的提示,应用启动:手动管理:检查所有三个位置:自动启动,二次启动,在后台运行.
The path to do this: Settings -> Security & privacy -> Location services -> recent location requests: YOUR APP NAME -> Battery -> uncheck Power-intensive prompt, App launch: Manage manually: check all three positions: Auto-launch, secondary launch, run in background.
我不知道是否有办法以编程方式执行此操作.我认为最好的方法是创建一种帮助活动,并向用户解释如果应用程序无法正常工作该怎么办.
I don’t know if there's a way to do this programmatically. I think the best way is to create a sort of help activity and explain the user what to do if application won’t work.
这篇关于当应用程序仅在华为设备中关闭时,服务被终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!