OnActivityResult not called for an already running activity

879 views Asked by At

I have an application with 3 layers. A, B, C. A and B are fixed and C can be any one of the multiple activities.

Application normally works in A>B>C direction. A calls B with startActivityForResult method. B calls C with startActivityForResult too and result of C is processed in B and passed back to A via onActivityResult methods on all layers.

It works fine but I somehow want the activity A to call C directly (where i have implemented a thread to do stuff in background) using

Intent i = new Intent("com.intentntfiltername.ACVITIY-C");
startActivity(i);

C then switches back to A by resuming it. After this A would call B for result. B would then call C using

intentName.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityForResult(intentName, requestCodeVariable);

that would not create new instance of Activity C but instead resume the old activity.

The problem is when I return to B after exiting C, onActivityResult is never called. It just resumes the B activity without processing any results from C.

i.e on Activity Result is not working when we try to call an already running activity for result.

Please tell me how to implement this. Or any other workaround only if its not possible for an already running activity.

1

There are 1 answers

3
tibbi On

when I finish an activity that was started for a result, I call for example

Intent intent = new Intent();
intent.putExtra("email", email);
act.setResult(RESULT_OK, intent);
act.finish();

where the returned value I needed is the email of course, and "act" is the activity that Ive created in the onCreate as

act = this;