2

I have 3 activities. Let's say A, B, C. Main activity is A.

I'd like to start B from A then start C from B, then close B when C opens. Finally upon closing of C pass data to A.

How's this possible especially with Intent and startActivityForResult? Is it at all possible with the two latter methods?

Thanks.

user1319668
  • 329
  • 1
  • 4
  • 16
  • Since B closes before C closes, I think you'll need another place to store the results of C so A can access them. You should consider a singleton, or perhaps overriding your Application object to hold onto this data. – Michael Krause Oct 28 '14 at 23:26
  • You can just start activity a from activity c and set all data in the intent. Provided ofc you have activity a as single activity. Then the on New intent method on activity A will be called. No need to set activity for result. –  Oct 28 '14 at 23:43

3 Answers3

3

Supose you are using a button, when you click the button to start the activity C, you can finish the activity B, and get the action in the activity A.

Use onActivityResult() on activity A. On this pont, you can start the activity C using startActivityForResult().

This way, when you finish C, you can pass data to A, again using onActivityResult().

Renan Ferreira
  • 2,122
  • 3
  • 21
  • 30
1

Renan Lopes Ferreira's reply did the trick. Cheers.

user1319668
  • 329
  • 1
  • 4
  • 16
0

You can always start B from A and C from B using Intents. As you are removing A from the stack, C cannot directly pass data to A using startActivityforResult() and onActivityResult). (Isn't it obvious, A doesn't even exist in memory). So for A to access C's data, you must store C's data somewhere, so that A can access it, the next time it is up. Now, here the other scenario would be store it as persistent or non-persistent data. If you want the data to be persistent, it is recommended to use Shared Preferences, Database etc. and if you want it to be non-persistent then you may use Singleton etc.

Refer : http://developer.android.com/guide/faq/framework.html

vkm
  • 548
  • 7
  • 23