Search code examples
androidback-buttononcreate

Android: how to use OnCreate() when pressing backbutton


When pressing the backbutton I want that, whatever screen will be loading, the onCreate() method will be executed. I want this because the screens must be refreshing when navigating through the app.

Do I need to override the back button method?

if(keyCode == KeyEvent.KEYCODE_BACK)
{

    }

Solution

  • When you press the back button, the onResume() method is called, so instead of using onCreate(), use this and do whatever you need to do for refreshing the activity.