Why does the first tab activity in Android live forever?

僤鯓⒐⒋嵵緔 提交于 2019-12-05 23:04:49

After putting some more logs in the activity's lifecycle methods, I found out that the onCreate() and onStart() methods are always created for the first tab, but the onResume() method is only called for the visible tab. So I will put my lazy initialisation code on the onResume() method to avoid the first activity bog down the application.

Possibly the TabActivity works internally in a similar way to a http://developer.android.com/reference/android/widget/ViewFlipper.html and that's why the first tab activity is always created despite not being visible.

Try changing the initial tab to 2..n and see if that is the tab that gets created. I am betting it has something to do with how Android handles the TabActivity. If that's true then you might be able to check which tab you're on for != null and use that as the first tab or default to 1 if null.

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