Switch back to previously selected tab after the activity is recreated

情到浓时终转凉″ 提交于 2019-12-11 15:46:12

问题


In my TabActivity the user may be asked to switch to browser activity for OAuth phase, and if the phase takes too much time, my activity will be killed. After the user switches back to my activity, its onCreate() method is invoked again and tabs are recreated.

So I would like to know if there is any simple way to switch back to previous tab, and keep the tab as what it was. For example, one of the tab views contains a ViewSwitcher child, and I want to switch back to the switched view after recreating the activity.


回答1:


Step #1: In onSaveInstanceState(), save the state of your tabs, flippers, etc., so you know where you were

Step #2: In onRestoreInstanceState(), call appropriate methods to restore your state (e.g., setCurrentTab()).




回答2:


You can use intent in TabHost to set content of that tab.

tabHost .setContent(new Intent(this, XYZ.class)));



来源:https://stackoverflow.com/questions/3032109/switch-back-to-previously-selected-tab-after-the-activity-is-recreated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!