How to keep my app service keep running even if app is closed from task manager in MI phone

淺唱寂寞╮ 提交于 2019-11-26 21:03:13

问题


My app has background service which keep on running even if app is killed from the task manager but when I have tested my app on MI(xiaomi) phone it kills my app service when I close the app from task manager and my service keep on running and work perfectly on all devices except MI even if I kill my app from task manager.

So how to keep my service running in background even when the app is killed from the task manager?


回答1:


MIUI has a built-in Security app. In the Security app there is a 'Autostart' section, where the user can configure which app can and which app can't run on startup. Your application is disabled default. You need to enable your app and also enable permission manager from permission section.




回答2:


you are not able to do that from code until and unless there is some api from xiaomi that gives you access to that functionality. I am guessing auto start manager is an app( with privileges of that of a system app, since part of xiaomi modified os) , hence not possible.

But if the device is rooted you can actually disable autostart manager.

Still whatsapp , facebook and many more apps doing this may be because of they have tie ups with Xiaomi to be in the whitelist. But its just a guess.




回答3:


You should select release build variant from android studio because MI has disabled debugging mode.



来源:https://stackoverflow.com/questions/31355084/how-to-keep-my-app-service-keep-running-even-if-app-is-closed-from-task-manager

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