Search code examples
androidmultitaskingwakeup

Android - Detect `App Became Active' from Mulitiasking?


I have developed an Android App that contains a list of information. I want the list to retrieve new data from the sever whenever the app 'wakes up' from multasking. Right now it just displays the old data and does not refresh.

Can someone tell me what function/method I am looking for?


Solution

  • Your app can be woken up in a few different ways... you probably want onResume(), but here are the other ones too:

    • onResume() is called when your activity is resumed from the background or if a dialog/popup was on top of it (this is where you should refresh your list)
    • onRestart() is called when your activity is brought to the foreground from the background
    • onCreate() is called when your activity is started with an Intent
    • onNewIntent() is called when your activity alive is in the background and started with an Intent

    The full list is in the Android Activity Lifecycle found here:

    https://developer.android.com/reference/android/app/Activity.html