Search code examples
androidandroid-activitylifecycleback

How do get an activity to reload when the user hits the back button in a child activity


I have an activity that launches the Contact picker in the onCreate method. When the user selects a contact, that user's ID gets passed to a new child activity. If the user presses the back key however, they get presented with a blank screen cause the onCreate doesn't seem to be getting called again.

I've tried, onRestart and onResume, which fix the back issue, but what happens it a race condition in which it will make the call to open up an Contact picker activity before the ID is passed to the child activity.

EDIT: I'm using API 2.3.3.

I've tried the overloading the onBack method in the child activity to launch a new activity. But doing changes how the rendering of the page changes is done. When you launch a new activity the new activity comes in from the right hand side of the screen, but when you hit back the normal implementation causes the previous screen to slide in from the left-hand side. If I overload the onBack to call a new activity, what happens is the user hits the back button and a screen comes in from the right hand side of the screen as opposed to the left. I would need to have the window sliding be the same as the default pattern.


Solution

  • You cannot call onCreate on back key pressed. However you can do one thing that finish your contact picker activity. Override the function onBackPressed in Child activity and start a new Activity there.