siraj
siraj

Reputation: 461

Activity - To restart the previous activity when click back key

You may find this question before.But I need to restart the previous activity when the button in the present activity is clicked.But I need to maintain in the present activity and the back button should launch activity based on the click of the button in the present activity.

Upvotes: 0

Views: 351

Answers (2)

Vineet Shukla
Vineet Shukla

Reputation: 24031

As you have not mentioned about the back activity whether it is fixed or not. I am assuming it is not fixed. You can try something like this:

  1. When you move from one activity to another then pass the activity name to another activity thru intent.
  2. Handle back key event and on back key press, start the activity which you have got thru intents.

Upvotes: 1

Quentin DOMMERC
Quentin DOMMERC

Reputation: 876

You can put everything that's on the onCreate on the onResume. check the activity lifecycle (google it) to see why this will work.

Upvotes: 1

Related Questions