TabHost刷新activity的方法
在android中,使用tabHost的时候,如果tab被点击,该tab所对应的activity被加载了,从别的tab切换回来的时候,activity不会再次被创建了(onCreate),所以要想每次点击tab都刷新activity,有如下方法:
方法1 把要刷新的对象添加到
@Override
public void onResume() {
super.onResume();
//代码
}
每次切换tab,该activity会调用次方法
但是这个方法有个问题,如果在此方法中加载下个activity,在这里,我们起名叫activity2。当activity2结束时,调用finish()方法,此时tab所对应的那个activity仍然会执行onResume()方法,重新刷新数据。
如果想避免这种情况,使用方法2:
tabHost.addTab(tabHost.newTabSpec(0 + "").setIndicator(tv1).setContent(new Intent(this, NewsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
tabHost.addTab(tabHost.newTabSpec(1 + "").setIndicator(tv2).setContent(new Intent(this, VideoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
使用 .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)就可以了。
原创帖,转发请注明出处:http://thierry-xing.iteye.com/blog/1630687
TabHost刷新activity的方法的更多相关文章
- android开发之Tabhost刷新
在android中,使用tabHost的时候,如果tab被点击,该tab所对应的activity被加载了,从别的tab切换回来的时候,activity不会再次被创建了(onCreate),所以要想每次 ...
- html-javascript前端页面刷新重载的方法汇总
记得我在兴安得力实习要转正的时候,我领导象征性的给我出了一套测试题目,里面就有js闭包和页面刷新等题目.今天把很久之前的测试题目之一,js页面刷新的方法以及页面自动刷新跳转和返回上一页和下一页等方法总 ...
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
报错如下:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test2/com.exampl ...
- ASP.NET页面刷新的实现方法总结
先看看ASP.NET页面刷新的实现方法: 第一: private void Button1_Click( object sender, System.EventArgs e ) { Response. ...
- 从零开始学android开发-用Intent启动Activity的方法
启动另外一个Activity,可以有的方法有用setClass()和Component Name 1. 先说在setClass启动一个Activity的方法吧: Intent intent = new ...
- js返回上一页并刷新的多种方法
js返回上一页并刷新的几种方法.参考链接:http://www.jbxue.com/article/11230.html <a href="javascript:history.go( ...
- Activity.startManagingCursor方法
http://blog.sina.com.cn/s/blog_6f14deb60100wd2n.html 总结一下Activity.startManagingCursor方法: 转 我们将获得的Cur ...
- JavaScript刷新页面的方法(包括Frame框架的刷新方式)
JavaScript刷新页面的方法 1 history.go(0) 去指定的某页 2 window.location.reload()刷新当前页面 window.location.relo ...
- js和php刷新页面的方法
js中3个最优的刷新页面的方法 window.location.reload(): window.history.go(0): document.execCommand(''Refresh''): p ...
随机推荐
- BZOJ 2879 NOI2012美食节
链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2879 CZ市为了欢迎全国各地的同学,特地举办了一场盛大的美食节.作为一个喜欢尝鲜的美食客,小M ...
- LeetCode_N-Queens II
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total numbe ...
- .net 中的DllImport
只有做成COM的C++ dll才能直接引用.没有做成COM的就只能用P/Invoke(DllImport)或者C++/CLI那种.不过P/Invoke容易类型对不上,所以要是函数多,最好用C++/CL ...
- android官方侧滑菜单DrawerLayout详解
drawerLayout是Support Library包中实现了侧滑菜单效果的控件,可以说drawerLayout是因为第三方控件如MenuDrawer等的出现之后,google借鉴而出现的产物.d ...
- How to find friends
How to find friends 思路简单,编码不易 1 def check_connection(network, first, second): 2 link_dictionary = di ...
- 利用autoit自动关闭指定标题窗口
最近使用PL/SQL Developer 比较两个数据库数据差异,因部分表上没有主键,PL/SQL 就会弹出一个确认框提示某某表没有主键.因为有很多表没有主键,就不停的弹出确认窗口,得不停的点击 ...
- 【转】20个Java 代码生成器
From: http://www.cnblogs.com/skyme/archive/2011/12/22/2297592.html 1.1 CodeSmith 一款人气很旺国外的基于模板的dotne ...
- Yii2 分页类的扩展和listview引用
Yii2 本身提供了不错分页选项供用户设置,但是实际项目中我们往往需要复杂一些的分页样式,例如下图所示的效果,上下翻页可用和不可用均用图标来替换.
- poj 2385 Apple Catching(dp)
Description It and ) in his field, each full of apples. Bessie cannot reach the apples when they are ...
- Ajax_post发送
$('#img_file_del_3').click(function() { var data={name:$('#img_file_del_3').attr('name')}; var url=' ...