Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - does onPostResume get called after fragment is resumed

I cant seem to find this answer using search engine but in the case of an activity hosting a fragment, when the activities onPostResume method is called, i am assuming that any attached fragments onResume methods will already have been called. who can confirm ?

like image 954
j2emanue Avatar asked Dec 14 '22 18:12

j2emanue


2 Answers

Native Activity

final void performResume() {
    ...
    mInstrumentation.callActivityOnResume(this);
    ...
    mFragments.dispatchResume();
    mFragments.execPendingActions();

    onPostResume();
    ...
}

Support FragmentActivity

protected void onPostResume() {
    super.onPostResume();
    ...
    onResumeFragments();
    mFragments.execPendingActions();
}
protected void onResumeFragments() {
    mFragments.dispatchResume();
}

So here it depends on whether you do stuff with fragments before or after calling super.onPostResume() in your @Override.

like image 156
TWiStErRob Avatar answered Apr 25 '23 11:04

TWiStErRob


turns out i had automatic build turned off in eclipse thats why when i tested it myself i was getting strange results. But for those wondering...

  1. first an activity resumes
  2. then a fragment resumes
  3. lastly the host activites onPostResume is called.

so fragments are resumed within the activities onResume method. But that is not guaranteed. The better approach would be to override onResumeFragment. This call back ensures the fragments are resumed.

like image 25
j2emanue Avatar answered Apr 25 '23 13:04

j2emanue