Davide Berra
Davide Berra

Reputation: 6568

Know when an Android app is moved to recent list

I would like to know if there's a way to know when an app goes from foreground to recent app list.

I need this because I want to save all the stuff before the user can swipe it away and kill it brutally

Upvotes: 0

Views: 102

Answers (1)

Pankaj Nimgade
Pankaj Nimgade

Reputation: 4549

Consider any type of data into two categories

  1. Atomic
  2. Semi-atomic

First one being obvious, you only save it with consent of user.
Example -> payment-transfer, sending-text etc

Second is something little subjective, as you would like to save it as temporary information like half written message which user didn't send which you can save temporarily ( given if user uninstalls the app this data won't be coming back -- but consider this with grain of salt as nobody will stop you from saving it remotely in cloud)

for android OnPause() callback is a good place to save, However if you are working with some drawing app, let a Handler() trigger a save every few seconds.

Upvotes: 1

Related Questions