2

I'm in the process of converting from an startActivity/Intent based model to a fragment based model. Is there any way I can preserve all my code which passes information to an activity (which I'm now converting into Fragments) via Intent??

hunterp
  • 15,716
  • 18
  • 63
  • 115

2 Answers2

0

Just to add there's a good answer here: Where/How to getIntent().getExtras() in an Android Fragment?

You can pass Bundles of data to Fragments using getArguments() and setArguments().

(this is not a full answer, sorry, but the other guy really posted a comprehensive explanation I wanted to link to.)

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
0

Fragments need to be in an activity though, so the information passing model hasn't changed at all. You just need to pass the appropriate data to each fragment from your activity. If you are passing the same data as before, the code that stuffs data into an intent's extras before calling startActivity() doesn't need to change. You just need to change how your activities handle the extras.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • No they don't. Especially if using the FragmentTabsPager, in which case, fragments are simply fragments all 100 of them, and there is 1 FragmentsTabPager which is an Activity – hunterp Aug 10 '11 at 02:45
  • Quote: 'A Fragment is a piece of an application's user interface or behavior that can be placed in an Activity.' Using tabs and/or a pager is just one way to manage fragments, still inside an activity. – Nikolay Elenkov Aug 10 '11 at 02:51
  • 1
    However, I have 100 activities, each of them have 1-10 extras that they expect from Intents. So that is 2-20 lines of code (get and set) over 100 activities that I have to change. major pain in the ass. – hunterp Aug 10 '11 at 02:57