I have a tab activity, and inside one tab I have activitygroup. Initially activity A is shown and from there I want to call activity B using startactivityforresult. How to achieve this?
in my activity A, I am doing this...
Intent i = new Intent(Entry.this, Child.class);
// Create the view using FirstGroup's LocalActivityManager
View view = GroupActivity.group.getLocalActivityManager()
.startActivity("child", i
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
// Again, replace the view
GroupActivity.gro开发者_开发百科up.replaceView(view);
This though takes me to activity B, there is no way for me to return to activity A from there.
Change startActivity to:
.startActivityForResult(i, .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
then add this method to ActivityA:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// See which child activity is calling us back.
switch (resultCode) {
case RESULT_OK:
{
//processing code goes here
}
default:
break;
}
}
and then when finish() is called on Activity B you should hit the 'OnActivityResult' method. You can also send an intent back to main activity by calling:
setResult(Activity.Result_OK, intent);
on Activity B.
精彩评论