Which method gets called in the parent activity when the user clicks on Back in the child activity?

StackOverflow https://stackoverflow.com/questions/20669504

  •  19-09-2022
  •  | 
  •  

문제

I have 2 activities in my Android app: A and B. A is the parent of B, as defined in the Android manifest. When stepping through my app with the debugger I've found that when I click on Up in the child activity, B, the onCreate() method of A gets called. But where does control pass to when the user clicks on Back in activity B? Which method of its parent activity, A, gets called?

I've read lots of stuff about navigation in Android, Back vs Up, etc., but I can't find an answer to this simple question. (I would like the Back button to behave like Up in my app but I can't get A's screen to update correctly when the user clicks on Back in B.)

도움이 되었습니까?

해결책

At least onResume() will be called when activity A becomes active again.

다른 팁

override onBackPressed method of activity A it will called when you press Back on Activity B

 @Override
public void onBackPressed()
{
     // code here to show dialog
     super.onBackPressed();  // optional depending on your needs
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top