使用 TabHost 和 LocalActivityManager 时未调用 Android OnResume
我设置了一个包含两个活动的 tabhost,由于我无法使用 TabActivity,所以我使用了 LocalActivityManager,但是当我切换选项卡时,不会为选项卡内的活动调用 onResume。这是我的设置:
mlam = new LocalActivityManager(this, false);
mlam.dispatchCreate(savedInstanceState);
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup(mlam);
我将dispatchResume和dispatchPause放置在适当的位置,但它们仅在主选项卡活动获得onResume或onPause时触发。我试图通过在 bab 更改时触发dispatchResume 来解决我的问题,但这似乎没有触发。
tabHost.setOnTabChangedListener(new OnTabChangeListener(){
public void onTabChanged(String tabId) {
mlam.dispatchResume();
}
});
有谁知道如何确保为活动触发 onResume ,以便我可以在选择选项卡时更新选项卡中的内容?
I set up a tabhost with two activities and since I could not use TabActivity I used LocalActivityManager, but when I switch tabs onResume is not called for the Activities within the tabs. Here is my set up:
mlam = new LocalActivityManager(this, false);
mlam.dispatchCreate(savedInstanceState);
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup(mlam);
I have the dispatchResume and dispatchPause placed in the proper places, but they only fire when the main tab activity gets an onResume or onPause. I tried to solve my issue by firing the dispatchResume on bab change but that seems to not be firing.
tabHost.setOnTabChangedListener(new OnTabChangeListener(){
public void onTabChanged(String tabId) {
mlam.dispatchResume();
}
});
Does anyone know how to make sure the onResume is fired for the activities so I can update the content within the tabs as they are selected?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用第二个参数 true 来初始化 mlam:
mlam = new LocalActivityManager(this, true);
然后 tabhost 中某个时间只恢复一项活动。
You have to initialize mlam with the second parameter true:
mlam = new LocalActivityManager(this, true);
And then only one activity is resume at the some time in the tabhost.