android - Why doesn't the tabwidget remain modified? -
in android have tabactivity (a) in create single tab called loading activity b.
from activity b modify tabwidget tabactivity add more tabs via static reference tabhost in tabactivity a.
after start new activity c , press tabwidget has 1 single tab called loading.
i've tried in onresume method of activity b recreate tabs doesn't work anymore.
does know why , how can fix it?
relying on static variables pointing ui components (like tabhost
) can lead produce memory leaks. don't it. instead register broadcastreceiver
in tabactivity
add new tabs. way, instead of modifying static variable, send broadcast (context#sendbroadcast(intent)
) tell tab activity want new tab.
also, make sure save state of tabactivity
, can restore if android os destroys activity reason. recommend using onretainnonconfigurationinstance
... this:
private state mstate; public void oncreate(bundle b){ // somewhere in oncreate mstate = (state) getlastnonconfigurationinstance(); if( mstate == null ){ mstate = new state(); } else { for(tabspec tab : mstate.tabs){ //add them tab host } } } @override public object onretainnonconfigurationinstance() { return mstate; } private static class state{ list<tabspec> tabs; // more stuff want save }
Comments
Post a Comment