Android - Service stops when swiping app from rece

2019-04-12 12:45发布

I've developed an android application with a service that runs in the background the service is called like that

startService(new Intent(getApplicationContext(),myService.class));

but when I remove the app from the recent apps, the service stops and it crashes if I test it.. is there a way to prevent the service from being destroyed when swiping the app from the recent apps?

thank you

1条回答
趁早两清
2楼-- · 2019-04-12 13:02

You can register a service to run on a repeating cycle using AlarmManager

http://developer.android.com/reference/android/app/AlarmManager.html

The service will run even if the application is not running.

查看更多
登录 后发表回答