0

I just want to show an alert box at just killing the application in android. It's like a Notepad application, if we simply kill the app (on clicking the close button) then we get an alert box asking for save changes.

I just want to add same thing in my application.I have tried onBackPressed() and its working fine on clicking on Back Button. But I need same thing on closing the application.

Kishan
  • 9
  • 1

1 Answers1

0

There is now way to be sure if the app is being closed but you can place a check if the application is in foreground or not which is a better metric IMHO as this tells you when the user moved away from your application.

To check the ProcessLifeCycleOwner this will help you find state of process. You can check this Github sample or this stackoverflow question in how to use it.

Taranmeet Singh
  • 1,199
  • 1
  • 11
  • 14