简体   繁体   English

从Tab Host击退按钮时未调用OnResume

[英]OnResume not called when hitting back button from Tab Host

I'm running into a pesky issue. 我遇到了一个讨厌的问题。 I have two tab hosts ... tab host A and tab host B . 我有两个标签主机 ... 标签主机A标签主机B。 Each tab host has three tabs (let's call them A1, B1, A2, B2, etc). 每个选项卡主机都有三个选项卡(我们称它们为A1,B1,A2,B2等)。 Tab host B is launched from Activity A2 . 选项卡主机B从活动A2启动 Anyway, here is my problem: 无论如何,这是我的问题:

When I'm in one of the tabs of tab host B and I navigate back to Activity A2 using the built in back button, onResume does not get called. 当我进入选项卡宿主B的一个选项卡中并且使用内置的后退按钮导航回活动A2时,不会调用onResume I don't understand why this is the case ... I read the article on the Activity Lifecycle and it seems to me that as soon as Tab host B launches that Activity A2's onStop method should have been called ... and that as soon as I navigate back to it with the back button that A2's onStart and onResume methods should have been called. 我不明白为什么会这样...我阅读了活动生命周期上的文章,在我看来,Tab主机B启动后,应该立即调用活动A2的onStop方法...当我使用后退按钮导航回它时,应该已经调用了A2的onStart和onResume方法。 The only thing that I can think of is that maybe Tab Host A's onResume is being called instead of Activty A2's on resume. 我唯一想到的是,也许正在调用Tab Host A的onResume而不是Activty A2的履历。 Any help would be much appreciated! 任何帮助将非常感激!

Here is the code I am using to kick of A2 from Tab Host A: 这是我用来从Tab Host A踢A2的代码:

intent = new Intent().setClass(this, FiltersActivity.class);
spec = tabHost.newTabSpec("filters").setIndicator("Filters",
       res.getDrawable(R.drawable.ic_tab_filters)).setContent(intent);
tabHost.addTab(spec);

The developer page´s comment inherit´s the answer 开发者页面的注释继承了答案

 // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, ArtistsActivity.class);

The activity is wrapped in your tab specification and it´s lifecycle is related to the specification now. 该活动包含在选项卡规范中,并且其生命周期现在与该规范有关。

What you might wanna do is provide your own method you call when you switch to a tab and call it. 您可能想做的是提供自己的方法,当您切换到选项卡并调用它时,即可调用该方法。

getTabHost().setCurrentTab(resumeTab);
Activity filtersActivity = this.getCurrentActivity();
filtersActivity.yourMethod();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从片段返回时,不会调用主页活动的 OnResume() - OnResume() is not called of the home activity when back pressed from a fragment 单击 android 上的电话硬件后退按钮时从未调用过 onResume? - onResume never been called when click the phone hardware back button on android? 击返回按钮时,listview丢失数据行 - android - listview losing the rows of data when hitting back button 在设备上或从底栏按下返回按钮时,不会调用 onBackPressed - onBackPressed is not called when Pressing Back button on Device or from Bottom bar 如何在点击返回按钮时从一个片段中调用另一个片段? - How to call another fragment from one fragment on hitting back button? 使用TabHost和LocalActivityManager时未调用Android OnResume - Android OnResume not called when using TabHost and LocalActivityManager 返回活动时未调用Android onResume() - Android onResume() not being called when returning to an Activity 按下向后箭头会调用onResume()。 请查看详细信息 - onResume() getting called on pressing back arrow. Please see details 点击后退按钮进入jsp页面 - go to jsp page by hitting back button 如果显示对话框,当用户按返回按钮时,调用哪种方法? - Which method is called when user presses back button if a dialog is shown?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM