Android TabActivity pass parcelable across tabs
-
12-06-2021 - |
문제
I'm trying to pass data from tab n to tab n+1 activities, based on TabActivity in the MainContainerActivity, using parcelables but can't succeed as I can not apply "getExtras" method on the tab n+1 intent.
I can pass my parcelable object from one tab to the next one if I start the tab n+1 activity using startActivity(nextactivity)
instead of using the tab switcher with tab.setCurrentTab(tab_n+1)
.
How shall I manage the activity intents sothat I can succeed to pass those parcelable objects, still implementing TabActivity in the MainContainer class and Activity in the tabs ?
or is there a way to force the activity start in the manifest when using tab.setCurrentTab(tab_n+1)
?
I read dozen of threads and have been trying many misc tests but w/o success so pls detail the answer as for a real noob :-)
EDIT: Looking to get this working from API8 onwards
해결책
As explained here :
Restarting an activity in a single tab in a TabActivity?
What you want is to destroy the activity and start it again, by passing the new Parcelable "arguments" in the intent. The suggested method will probably work, however I strongly suggest you to consider using Fragments instead. If you want to support version prior Android 3, you will need the support package. The examples listed in this thread: https://stackoverflow.com/questions/5710573/need-a-fragments-example should get you started on Fragments.
다른 팁
I guess the simple answer to my simple 3 tabs application is using a global object as described here, which also allow keeping my existing source code.