1

I have 3 activities: A, B and C. I'd like to launch C from A and send back the result to B using onActivityResult():

  • A launch C using startActivityForResult()
  • C is launched and performs its task
  • B received the result of C in onActivityResult()

Is it possible?

Benjamin
  • 7,055
  • 6
  • 40
  • 60
mba3gar
  • 99
  • 1
  • 11
  • yes possible. please check with this url https://stackoverflow.com/questions/10407159/how-to-manage-startactivityforresult-on-android – srinu Mar 15 '18 at 13:27
  • 1
    You can not do this directly . You need to do chaining A->B->C . The result will back as C->B->A . – ADM Mar 15 '18 at 13:28
  • Possible duplicate of [How to manage \`startActivityForResult\` on Android?](https://stackoverflow.com/questions/10407159/how-to-manage-startactivityforresult-on-android) – ADM Mar 15 '18 at 13:28
  • Yes of course. But not like you think it can. Just start activity C with the relevant data, you obtained in the onActivityResult of activity B, put in the intent you use to start C. – greenapps Mar 15 '18 at 13:29
  • @greenapps but does it affect the phone performance to close C and launch B from A? – mba3gar Mar 15 '18 at 13:32
  • There is nothing in your or my post that tells us that B is launched from A. On the contrary. You suggest that B is started form C. You could update your post to better tell what you want to happen as it is very confusing. – greenapps Mar 15 '18 at 13:38
  • You did not even tell in which activity that onActivityResult happened. – greenapps Mar 15 '18 at 13:41
  • @greenapps on activity result is set in activity B so A send to C C send B and on activity result is in B – mba3gar Mar 15 '18 at 13:42
  • Please update your post. I asked that befor.e You wrote a confusing post. Further: `on activity result is set in activity B so A send to C C send B and on activity result is in B ` ??? I do not understand a word of this. – greenapps Mar 15 '18 at 13:43
  • @greenapps check now the post is it more clear ? – mba3gar Mar 15 '18 at 13:48
  • No. It makes no sense. – greenapps Mar 15 '18 at 14:43

2 Answers2

1

Its not directly possible because the result of Activity C will return to Activity A when C finishes. If you want to open Activity B after Activity C send result to A, start the activity B from onActivityResult (when result comes from C to A), passing the data you received from C to B using A.

But if your Activity B is not related like above, you can store the result from Activity C in SQLite DB and then when activity opens read the result from SQLite and show in activity B

Umar Hussain
  • 3,461
  • 1
  • 16
  • 38
0
 yes it is possible please do like this.

  Intent intent=new Intent(MainActivity.this,ActivityC.class);  
            startActivityForResult(intent, 2);// Activity is started with 
       requestCode 2  


    @Override  
      protected void onActivityResult(int requestCode, int resultCode, 
     Intent data)  
         {  
             super.onActivityResult(requestCode, resultCode, data);  
              // check if the request code is same as what is passed  here 
            it is 2  
               if(requestCode==2)  
                     {  
                        String message=data.getStringExtra("MESSAGE");   
                        textView1.setText(message);  
                       //for here you can start your Activity B with data 
                      whatever you want to send to Activity B.
                     }  
               }  

and form Activity c set the result like

   Intent intent=new Intent();  
                intent.putExtra("MESSAGE",message);  
                setResult(2,intent);     
umesh shakya
  • 237
  • 2
  • 12