farhad.kargaran
farhad.kargaran

Reputation: 2373

I want to be informed if my app is no longer visible or killed

I want to run a SERVICE when my app is no longer visible for example if the user pressed home button or killed my app. how can I implement that?

Upvotes: 0

Views: 67

Answers (3)

Bills
Bills

Reputation: 798

You can override onPause method, which runs when user presses home button and your application go in background, and onDestroy which called back when your application is been killed.

Check this

Upvotes: 0

Gagan Sethi
Gagan Sethi

Reputation: 407

You can run that service in onPause of a Activity. OnPause is Called when the user press home button. For Back Button, OnStop is Called. It won't work if the application crashes.

Upvotes: 0

Anil Olakkal
Anil Olakkal

Reputation: 3894

You can run that service in onStop of a Activity. Onstop is Called when the activity is no longer visible to the user. It won't work if the application crashes.

Upvotes: 2

Related Questions