[英]Android: onActivityResult() is not calling for startActivityForResult
I have an Activity named Main
. 我有一个名为Main
的活动。 I am calling another activity Sub
from this Main
activity using startActivityForResult()
. 我正在使用startActivityForResult()
从此Main
活动中调用另一个活动Sub
。 And I want to take the result of this Sub
activity using onActivityResult()
function. 我想使用onActivityResult()
函数获取此Sub
活动的结果。
I can call the Sub
activity. 我可以调用Sub
活动。 But when return from Sub
activity, it is not calling onActivityResult()
function. 但是当从Sub
活动返回时,它没有调用onActivityResult()
函数。 So I can't get the result of the Sub
activity. 所以我无法获得Sub
活动的结果。
Actually my Main
activity is starting from MainGroup
activity by using startActivity()
function, which extends ActivityGroup
. 实际上,我的Main
活动是通过使用startActivity()
函数从MainGroup
活动开始的,该函数扩展了ActivityGroup
。
Is there any way to take the activity result without calling onActivityResult()
? 有什么方法可以在不调用onActivityResult()
情况下获取活动结果?
Actually I am calling an activity for PayPal Preapprovals. 实际上,我正在呼叫PayPal预批准活动。 And the activity Which I am calling is on the PayPla library (.jar file). 我正在调用的活动在PayPla库(.jar文件)上。 So I can't modify that activity. 因此,我无法修改该活动。 And when I am implemented this in another application without ActivityGroup, this is working fine 当我在没有ActivityGroup的另一个应用程序中实现此功能时,它工作正常
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: 要调用onActivityResult()
方法,必须确保requestCode与PreapprovalIntent中使用的requestCode (例如,此处YOUR_REQUEST_CODE )相匹配:
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: 因此,在您的onActivityResult()中,您应该具有以下内容:
@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()
. 它应该可以工作,但是我实际上对Activity结果有一个问题:我的代码不是调用Activity.RESULT_OK ,而是在onActivityResult()
调用Activity.RESULT_CANCELED 。 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. 甚至很奇怪,因为一旦显示PayPal活动,就会调用onActivityResult()
代码。
sorry to tell you this, but PayPals' API and documentation is a mess. 不好意思告诉您,但是PayPals的API和文档一团糟。 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获取活动结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.