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 no开发者_如何学JAVAt 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 (e.g 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 ;-))
i think you are doing really wrong imple.if you want to get result of sub than you have to write startActivityForResult() for sub activity and and get activity result from main
精彩评论