Android的 - 在一定的时间间隔清爽的页面数据最佳实践方法? [英] Android - best practice approach for refreshing page data at a certain interval?

查看:122
本文介绍了Android的 - 在一定的时间间隔清爽的页面数据最佳实践方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,出去到数据库并获取最新的数据。问题在于,多个用户可以访问该数据。因此,如果有人增加了数据,当前屏幕不更新,用户是一头雾水。

I have a page that goes out to the database and gets the latest data. The problem is that multiple users can access that data. So if someone adds to the data, the current screen does not update, and the user is confused.

什么是不断刷新用户的页面上的数据的最佳方式?我应该发送一个呼叫服务器每隔30秒左右,以获得最新的?如果这是唯一的方法,我必须做出一个新线程?如何最能实现的?

What is the best way to keep refreshing the data on the page for the user? Should I send a call to the server every 30 seconds or so to get the latest? If that is the only approach, do I have to make a new thread for that? How is that best accomplished?

谢谢!

推荐答案

假设你正在使用的WebView ,你可以尝试这样的事情,

Assuming you are using a WebView, you can try something like this,

// Wait 60 seconds before reloading
private static final int WAIT_TIME = 60000;

mWebView = (WebView) findViewById(R.id.MyWebView);
mWebView.loadUrl(/* ENTER URL HERE */);

new Timer().schedule(new TimerTask(){
    @Override
    public void run() {
         mWebView.reload();
    }
}, WAIT_TIME, WAIT_TIME);

这篇关于Android的 - 在一定的时间间隔清爽的页面数据最佳实践方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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