Please give me some suggestions how to pass object between fragment and activity.
In my project, there is one FragmentActivity to show and edit customer profile. Multiple tabs will be contained in this activity to show contact info, address... The customer info will be preload as one class in the activity. My question is how could I pass this object to each fragment or tab? Once updated, how could I pass back to activity?
Do I must to implement the Parcelable interface in my customer class to pass by bundle?
Each tab will be dynamic created, is possible to get the fragment instance to modify view directly? If yes, once tab switch, is fragment destroyed?
Thanks
Myron
You need to know how interfaces work and how to set tags to a fragment as well as how you find a specific fragment by tag. You should read this...
http://developer.android.com/training/basics/fragments/communicating.html
To send objects to you fragments this are the basics. On the activity....
On the fragment...
where getShownIndex is....
If you wanna communicate from the fragment to the activity then you need interfaces.
No doubt: best solution is to call an activity method from the fragment:
Here an example with a Bitmap Object.
In ACTIVITY:
define your method:
In FRAGMENT:
1 - Define your activity
2 - Link your activity
3 - Call your method!
Quick and easy!