简体   繁体   中英

Android: onActivityResult() is not calling for startActivityForResult

I have an Activity named Main . I am calling another activity Sub from this Main activity using startActivityForResult() . And I want to take the result of this Sub activity using onActivityResult() function.

I can call the Sub activity. But when return from Sub activity, it is not calling onActivityResult() function. So I can't get the result of the Sub activity.

Actually my Main activity is starting from MainGroup activity by using startActivity() function, which extends ActivityGroup .

Is there any way to take the activity result without calling onActivityResult() ?

Edited

Actually I am calling an activity for PayPal Preapprovals. And the activity Which I am calling is on the PayPla library (.jar file). So I can't modify that activity. And when I am implemented this in another application without ActivityGroup, this is working fine

Please help me..

Thank You...

to get the onActivityResult() method called, you have to ensure that the requestCode match the requestCode (eg here YOUR_REQUEST_CODE ) used in the PreapprovalIntent:

  Intent preapproveIntent = PayPal.getInstance().preapprove(
      preapproval, getBaseContext());
  preapproveIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  startActivityForResult(preapproveIntent, YOUR_REQUEST_CODE);

so in your onActivityResult() you should have something like:

@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {

    switch (resultCode) {
      case Activity.RESULT_OK:
        if (requestCode == YOUR_REQUEST_CODE) {
          Log.i("RESULT", "IT WORKS");
        }
        break;

      default:
        break;
    }
  }

it should work, but I had an issue with the Activity results actually: instead of calling Activity.RESULT_OK , my code invokes Activity.RESULT_CANCELED in onActivityResult() . Which is really weird since I am sure my preapproval process works. It is even weird since the onActivityResult() code is invoked as soon as the PayPal Activity is displayed.

sorry to tell you this, but PayPals' API and documentation is a mess. If some of you had the same issue, please let me know how you solved it (if you solved it ;-))

我认为你做错了imple.if如果要获取sub的结果,则必须为子活动编写startActivityForResult()并从main获取活动结果

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM