Service Automatic Called on Destroying Activity

后端 未结 4 945
天涯浪人
天涯浪人 2020-12-16 15:17

I am stuck with the problem of Activity + Service in that I have following number of Activities and Services.

Activities:

4条回答
  •  忘掉有多难
    2020-12-16 15:59

    Services got killed when application got killed (add logs in service onStartCommand() and onDestroy() function and try clearing app from recent list and you will see onDestroy() is called. Android will re-start service if you have returned START_STICKY intent in onStartCommand()).

    There are two approaches to fix your problem.

    1. Either make your two services as foreground service.

    2. Instead of using CheckAutoSyncReceivingOrder and CheckAutoSyncSendingOrder to schedule start of another services, you should use AlarmManager to schedule your task.

提交回复
热议问题