service killed when app cloes just in huawei device

匆匆过客 提交于 2021-02-10 14:14:42

问题


I make service to Toast a text always but just in huawei device service killed when i kill app.
I don't know why?

My service is:

@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");
} 

回答1:


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.




回答2:


You should stop the service on the method @Override onDestroy()



来源:https://stackoverflow.com/questions/48559465/service-killed-when-app-cloes-just-in-huawei-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!