Search code examples
androidandroid-studioandroid-activityandroid-manifestactivity-lifecycle

Why is my Activity runs from the top again when resumed instead of doing nothing?


I have an activity which displays a table from the database. When I press power button to turn off the screen, then pressing power button again to resume the activity, the table loads again and does what it did on create. Why is my activity running again when I resume it?

I even put onResume() and left it blank/default.

@Override
protected void onResume() {
    super.onResume();

}

Solution

  • Accordingly, it will call methods according to as follows, that will never call for onCreate() so that your data is reloaded,

    On launching Activity it will call --> onCreate(), onStart(), onResume(),

    onPower Key Off --> onPause(), onStop()

    onPower Key On --> onRestart(), onStart(), onResume()

    To prevent reloading your data there are many cases this and this link

    May be due to :

    android:configChanges="orientation|keyboardHidden|screenSize"