9

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Edward
  • 139
  • 3
  • 9
  • It depends on android os for making this decision to free resources. You can have a look on `IntentService` to have more optimized way of using background services. – Jibran Khan Jul 11 '15 at 08:32
  • @JibranKhan but my service is running on ll device even if i kill app..because i am sending an broadcast when on destroy get fired .. but only in xiaomi it is not working... – Edward Jul 11 '15 at 09:02
  • Well `onDestroy()` itself is not guaranteed to be fired every time app closes or exits. Also do check if there is anything to do with android versions in your 2 other phones as compared to Xiaomi – Jibran Khan Jul 11 '15 at 09:09
  • @JibranKhan but on the same device whats app service keep on running all the time it consumer much more memory than my service why so..? – Edward Jul 11 '15 at 09:45
  • @Edward if its not late, you can check this link - http://stackoverflow.com/a/41360159/2798289 – Govind Dec 30 '16 at 06:07
  • @Edward did you found the solution? – Moorthy Sep 16 '17 at 18:42

2 Answers2

6

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.

Chirag Kheni
  • 184
  • 1
  • 8
  • 11
    But user doesn't gonna do this him/her self so is there any other way to do it programmatically w/o user interaction – Edward Aug 31 '15 at 13:10
  • I have did it in MIUI 8 and removed app from task manager and app background service has been stopped.... – Himanshu Jan 07 '17 at 11:17
  • @himCream how you did this in programmatic way. Can you please share the code. I've been waiting for long time to fix this issue. Thanks in advance. – Moorthy Sep 16 '17 at 18:21
  • @moorthy sorry, I din't get, Which code do you want from me? – Himanshu Sep 18 '17 at 07:34
  • To make our app into whitelist by programmatically (i,e how to do we enable auto-start for our app) – Moorthy Sep 18 '17 at 09:41
0

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

Soni Kumar
  • 283
  • 1
  • 4
  • 16