How to stop Android service when app is closed

前端 未结 3 1298
情深已故
情深已故 2021-02-01 03:52

I\'m trying to keep service running continously until user close app.

I\'m using startService() method from onCreate() method of my main activi

3条回答
  •  失恋的感觉
    2021-02-01 04:29

    Start by adding the android:configChanges node to your Activity's manifest node for stoping restart activity when device rotate.

    android:configChanges="keyboardHidden|orientation"
    

    Now for detecting a closing application event, think the ways user can close app manually. In android, by pressing a back button or home button. So put an event key listener for back & home button and terminate the service.

提交回复
热议问题