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

2

2

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

Chlorinate answered 3/8, 2016 at 6:8 Comment(5)
Lame question: Did you try subsequently reading the data in onActivityResult() and then setting it as setResult() in your chain linked activities?Bilow
i want to return response from third activity to seller app, anyway, i made setResult for only third activity only. here, i did not want pass data from chain activities in client app. I just want to send response data to Seller App onActivityResult.Chlorinate
So, let me know if I'm getting this right. The seller app is followed by the client app where the user navigates to third activity where she generates data which is to be sent to seller app (possibly via setResult())Bilow
yes. you are on correct path.. that''s my scenario.Chlorinate
thank you for reply sugar..last activity we set setResult is correct. But, i want to send the response to seller app , not first activity..Chlorinate
B
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 :).

Bilow answered 3/8, 2016 at 7:14 Comment(2)
thank you for reply. for first suggestion, i want to change my overall app activity code to fragment code.Its Big change for me..but, will think final way this one.Chlorinate
second one, i have already tried, in third activity, i setted for setResult().when get back to Seller app, Its calling onActivityResult() successfully, but, Intent data is getting null is coming..this method not worked out..Chlorinate
P
-1

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();
}
Planchet answered 3/8, 2016 at 12:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.