我怎样才能刷新活动? [英] How can I refresh the activity?

查看:120
本文介绍了我怎样才能刷新活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要刷新的活动,因为我想thatwithout烧制一些工作得到执行和活动本身要求的任何事件。所以,我想知道的是有Android中的任何选项本身刷新活动。

I want to refresh the activity as i want thatwithout firing any event some work gets performed and activity calls by itself. So, i want to know is there any option in android to refresh the activity by itself.

推荐答案

您可以自己通过在其上调用postDelayed(..)处理程序做到这一点。

You can do this by yourself through a Handler on which you call postDelayed(..)

http://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable,长)

将这个:

private final Handler handler = new Handler();

进行调用的函数:doTheAutoRefresh(),做:

make a function called: doTheAutoRefresh() that does:

private void doTheAutoRefresh() {
    handler.postDelayed(new Runnable() {
             @Override
             public void run() {
                 doRefreshingStuff(); // this is where you put your refresh code
                 doTheAutoRefresh();                
             }
         }, 1000);
}

调用此函数在你的onCreate。

Call this function in your onCreate.

请注意:这是基本的做法。考虑停止在此之后的onPause已经调用了onResume后恢复它。看看处理程序类,看看如何删除。

NOTE: this is the basic approach. consider stopping this after onPause has been called and to resume it after onResume. Look at the handler class to see how to remove.

这篇关于我怎样才能刷新活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆