1

I have a tabhost on my application and I'm using an Activity group which handles 3 activities inside.

Example: ActivityGroup Handles A -> B -> C

When i start this activities i'm using the flag Intent.FLAG_ACTIVITY_CLEAR_TOP.

My problem is when the user goes from A->B->C and press back button, my B activity shows up, but it does not resume or reload or refresh. It has the same state as before.

For example if the user goes again to C, C is refreshed, but when from C goes back.... B is not.

On B I have implementend methods such as onResume, onStart, onReestart and debugging it the main thread never goes in there...

And i need to refresh B because C can make changes that change the content displayed on B.

I have googleled this for 3 days and I couldn't found a solution..

sluceno
  • 11
  • 1
  • 2
  • you can use startActivityForResult(); –  Apr 20 '11 at 07:12
  • You should write those code on onResume() of B, which are responsible for displaying content. Even you have to populate data in onResume method if you are trying to access some data. If its not clear post your oncreate method of B, and mark which should be change after C call. – Pankaj Kumar Apr 20 '11 at 07:47
  • I know, I have overwrite the onResume method, but this method is never called. I debugged with some breakpoints, but the execution thread never gets into onResume... I also tried onReestart and onStart... – sluceno Apr 20 '11 at 18:13

5 Answers5

2

I had this problem too.

I was using ActivityGroup code based on this blog post.

When I pressed the back button the pervious View would load fine, but the activity associated with it would not fire the onResume().

I was using an extended activity with on overridden and public onResume().

I found this blog post, so tried casting the view as my extended activity and called onResume().

Bingo.

Edit.... here's some more detail...

public class YFIMenuListActivity extends ListActivity {
....
  @Override
  public void onResume() {
    super.onResume();
  }
....
}

onResume() is normally protected, but I override it and make it public so that my ActivityGroup can call it. I only have extended list activities in this activity group (I was just playing around). If you have different activities, each will have to override onResume() and I guess you'd have to look at the type of context you got back from v.getContext() before casting and calling it.

My ActivityGroup looks something like this:

public class BrowseGroup extends ActivityGroup {
.....
  @Override
  protected void onResume() {
    super.onResume();
    // call current activity's onResume()
    View v = history.get(history.size()-1);
    YFIMenuListActivity currentActivity = (YFIMenuListActivity)v.getContext();
    currentActivity.onResume();
  }
....
}
cousin_itt
  • 51
  • 4
  • I am having the same problem i guess, right now with the onResume , it goes back to the previous activity, when i changed orientation – Mikey Jun 29 '11 at 15:53
  • @cousin_itt I am also having the same problem, but I am not able to call the onResume(), please let me know how to call the OnResume() in that case. – Lalit Poptani Aug 05 '11 at 18:47
  • Hi, sorry for delay. I've added some detail to my answer now. – cousin_itt Aug 05 '11 at 21:41
  • @cousin_itt I had asked this question on SO, so you can answer there so that I can check mark that as an answered so that every else can also get benefit from there. Here is my question Link http://stackoverflow.com/questions/6964287/onresume-not-called-by-pressing-back-button-in-activitygroup/6964316#comment-8305042 – Lalit Poptani Aug 06 '11 at 05:10
1

I've managed to implement an expanded version of cousin_itt's approach.

In both of my activities being used within the activity group I changed onResume from :

protected void onResume()

to

public void onResume()

I then wrote the following onResume function in my ActivityGroup to manually fire off onResumes:

@Override
protected void onResume() { 
super.onResume();
View v = history.get(history.size()-1);

MainPeopleView currentActivity = null;   

try {
    currentActivity = (MainPeopleView)v.getContext();
    currentActivity.onResume();
}
catch ( ClassCastException e ) {
    Log.e(TAG, e.toString());
}

ProfileView otherActivity = null;

try {
otherActivity = (ProfileView)v.getContext();
otherActivity.onResume();
}
catch ( ClassCastException e ) {
    Log.e(TAG, e.toString());
}
}

I have to say, this feels like the worst android hack I've ever written. I'm never using activitygroup again.

Evan
  • 749
  • 6
  • 11
1
((ReportActivity)getLocalActivityManager().getActivity("ReportActivity")).onResume();

ReportActivity is that name you want to back Activity ps: v.getContext();

only return the ActivityGroup ,it can't invoke child Activity onResume

huntersea
  • 29
  • 3
0

I hope you have write your refresh data code in this method onResume().

Taryn
  • 242,637
  • 56
  • 362
  • 405
SBJ
  • 4,089
  • 3
  • 24
  • 27
0

I have found that onFocusChanged(boolean hasFocus) is great for situations like ActivityGroup. This will fire, even if onResume() does not. I use it for a few of my apps that have TabHosts and ActivityGroups. Here you can force the refresh and insure that it always gets fired when your Activity regains the focus.

Fuzzical Logic
  • 12,947
  • 2
  • 30
  • 58