Call Onrestart/onresume When Click On Back Button
Solution 1:
@Commonsware kindly pointed out (in another post of mine) that ActivityGroups have actually been deprecated. We are supposed to be moving onto to Fragments, instead.
Been battling with the same problem as you for longer than I care to admit. None of the commonly used tools (OnResume, OnRestart) work when you return the focus to a view from within an ActivityGroup after pressing the back button.
Unfortunately, I still need to find a way to fake an onResume when the from within the ActivityGroup after the back button is pressed (since I am heavily invested in this legacy code that uses ActivityGroups.) On I struggle.
Hope this helps.
-- edit --
I found a way to do this:
Instead of keeping a history of the views, keep a history of the id's of the the activities you start. Every activity you start has a unique id associated with it. So, when you call back(), retrieve the activity's id, and start the activity anew. This will trigger your activity's "onResume()" method as you desire.
Here is how I would restructure the code you provided: following bit to load a new view:
Intent intent = new Intent(Start.this, CitySelect.class);
View view = TestActivity.group.getLocalActivityManager().startActivity("cityselect", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
TestActivity.group.replaceView(view,"cityselect");
Replacing the view within the "replaceView()" method:
public void replaceView(View v, String activityId)
{
history.add(activityId);
setContentView(v);
}
And finally, the back() method from within the ActivityGroup:
public void back()
{
if (history.size() > 0)
{
history.remove(history.size() - 1);
if (history.size() > 0)
{
//View v = history.get(history.size() - 1);
//setContentView(v);
LocalActivityManager manager = getLocalActivityManager();
String lastId = mIdList.get(history.size()-1);
Intent lastIntent = manager.getActivity(lastId).getIntent();
Window newWindow = manager.startActivity(lastId, lastIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
setContentView(newWindow.getDecorView());
}
else
{
finish();
}
}
else
{
finish();
}
}
Hope THIS helps a little more :)
Post a Comment for "Call Onrestart/onresume When Click On Back Button"