How to get data onActivityResult from external App Activity using seResult or startActivityForResult

放肆的年华 提交于 2020-01-04 07:01:29

问题


I have two application separately.Client and Seller App. I want to pay money for client app and get response to seller app. Anyway,i have deep linking concept enabled in seller app. Client App : It has three Activity Page inside client app.getting details(first activity page) and show confirmation(second activity) and payment is third Activity. Note:Open Client App using Seller App, fill all details and payment from client app and send response to Seller App. for this client side i have set code for this:

Intent object = new Intent();
object.putExtra("data", "3434434343343");
setResult(Activity.RESULT_OK, object);
finish();

for Seller App Code:

protected void onActivityResult(int ResCode, int ReqRes, Intent data) {

super.onActivityResult(ResCode, ReqRes, data);

if (ResCode == 1 && ReqRes == Activity.RESULT_OK && data != null) {

String response = data.getStringExtra("data");

}
}

Problem Here: from client side Successfully passing Data using setResult.then, Seller app activity successfully calling onActivityResult also,But, Intent data is coming as NULL only.Because,here client side am using multiple activities using then only, am passing result.thats my problem. If anyway is there to get the onActivityResult from multiple chain link activities( external App Activities) means, its useful for me.

Note: I have found one solution, if two App having a single activity means, Its properly setresult and OnactivityResult is calling and getting data.But, My scenario if for Multiple chain link Activities for Client Side App.

Please any help to come out this Issue. Thanks Advance


回答1:


Based on your use case scenario above, I believe a better architecture which would allow such a communication would be if the client app utilizes a Fragment based setup. Here, you can start the client activity from the seller app, let the user navigate to different fragments there and then use setResult() whereever suitable. Since, this is a one-to-one activity result setting behavior, it should work.

Another suggestion which you can try, given you don't want to go the fragment way is within the client app, as the user travels to different activities you can immediately call finish() in them and then in the final activity call setResult(). This probably won't work but, a [very] small part of me says it might :).




回答2:


You can navigate from ThirdActivity to FirstActivity, then return back to your seller app in the onNewIntent method of your FirstActivity.

After all the three procedures finished, your client app should have the following stacks.

FirstActivity -> SecondActivity -> ThirdActivity

And your ThirdActivity is on the top of the stack. Your ThirdActivity can navigate to the FirstActivity by using the following code

Intent toFirstIntent = new Intent(this, FirstActivity.class);
toFirstIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
toFirstIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(toFirstIntent);
finish();

Then in your FirstActivity, you can set the data and return to your seller app.

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Intent data = new Intent();
    data.putExtra("data", "12345678");
    setResult(RESULT_OK, data);
    finish();
}


来源:https://stackoverflow.com/questions/38735674/how-to-get-data-onactivityresult-from-external-app-activity-using-seresult-or-st

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!