简体   繁体   English

应用程序几个小时后停止刷新?

[英]App Stops refreshing after a couple of hours?

I build a printer app that i need to run 24/7 to check if there is new order, I wrote a code that refreshes the activity every 60 seconds to check if there's a new order. 我构建了一个打印机应用程序,我需要每周7天,每天24小时运行以检查是否有新的订单,我写了一个代码,每隔60秒刷新一次活动,检查是否有新的订单。 The problem is that it runs fine for an hour or so but after that the activity stops refreshing automatically until i click the refresh button. 问题是它运行正常一个小时左右,但之后活动会自动停止刷新,直到我点击刷新按钮。 Then again it works for an hour or so and again stops refreshing automatically. 然后它再工作一个小时左右,并再次自动停止刷新。 Can somebody please help me with this? 有人可以帮我这个吗?

I've use the following code to refresh the activity. 我使用以下代码刷新活动。

private static final int delay = 60;
Timer timer;
OrderAdapter oadaptor;
timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    getLiveOrders(bID,"ALL");
                    oadaptor.notifyDataSetChanged();
                    }`enter code here`
            });

        }
    }, 0, delay * 1000);

You shouldn't be doing that with a Timer but a service instead. 您不应该使用Timer而是使用服务 That way it will continue running even if the app is in the background. 这样,即使应用程序在后台,它也会继续运行。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM