I have an Android application with a main activity that is the tabhost. I'm adding multiple tabs to the tabhost with an intent to several activities.
My problem is that these activities are not created (onCreate is not called) until I click on the tab. This is a problem because I need to register broadcastreceivers: there may be broadcasts that are sent -before- a particular tab is opened.
I tried to work around this by:
- Setting my receivers as static and registering from somewhere else. This is not possible because I need to call into methods.
- Calling into tabHost.setCurrentTabByTag(the_tag) and then switching back to my root tab. This only works sometimes and this is a very ugly solution imo.
- Not using activities but just using views instead. Also not a very elegant solution because it turns my tabHost activity into one huge master class doing all kinds of unrelated things.
What would be the best solution to this problem? Can I somehow make sent broadcasts 'queue' instead of just disappearing when there are no receivers? Can I force creation of the my tab activities (this is not a problem, my users are almost guaranteed to use every single tab at some points)? Other ideas?
edit:
According to CommonsWare in this question; http://stackoverflow.com/questions/2945274/android-tabhost-update-tabs-from-tabs-activity
It may be a better idea to implement the tabs as views instead of activities... That somewhat changes my question:
How do I seperate different kinds of logic in the same activity? Not really looking forward to 30+ method uberactivity.