简体   繁体   中英

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. 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. That way it will continue running even if the app is in the background.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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