1

I have 3 Activities: A, B, C.

I want that Activities work as follows:

A startActivityForResult B; B can start C or send result to A; C can go back to B or send result to A.

When B send result to A, B must be removed from backstack. When C send result to A, B and C must be removed from backstack.

I'm not able to send result to A from C. This means that A must be reusmed (NOT RECREATED) and onActivityResult() must be callled to process result:

I have tryed with this code but A is recreated and onActivityResult() is not called!!

public class C extends Activity{
    sendResultToA(){
        Intent i = new Intent(getActivity(), A.class);
        i.putExtra("dataBean", dataBean);
        i.putExtra("args", "save");
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        getActivity().setResult(Activity.RESULT_OK, i);
        startActivity(i);
    }
}

Any ideas to solve this problem? Thank you

4

1 に答える 1

5

はい、この問題を解決できます。

From Activity A -> startActivityForResult(ActivityB)

From Activity B -> startActivityForResult(ActivityC)

すべて成功した場合は、次の方法で結果を設定します。

Intent i = new Intent();
i.putExtra("dataBean", dataBean);
i.putExtra("args", "save");
setResult(Activity.RESULT_OK,i); //pass your intent
finish(); // Call finish to remove ActivityC from the stack

ActivityB で成功した場合は、同じことを行います。とを使用して、onActivityResult結果が成功したかキャンセルされたかを確認 します。Activity.RESULT_OKActivity.RESULT_CANCELED

于 2013-06-12T08:54:19.650 に答える