开发者

how to call startactivityforresult from one activity to another within a activity group inside a tabwidget

开发者 https://www.devze.com 2023-03-14 19:47 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消