开发者

Android handler question

I have an application that needs to update a ongoing_event notification. The notification has a progress bar that i need to increment every 5 minutes. I use Handlers but something about it bothers me or i simply dont understand how they work.

      if (progress<=24)
           {

    contentView.setProgressBar(R.id.status_progress,24,progress,false);
    Toast.makeText(getApplicationContext(),progress, Toast.LENGTH_SHORT).show();
    progress++;
    mnNotificationManager.notify(IS_PARKED_ID, notification);
    mHandler.postDelayed(mUpdateTimeTaskProgressbar, 300000);

           }

here is the code. It appears that when the device screen is off the notification isn't being updated. I have used Handlers in the past but as i can recall i had them updating on every 100 milisec. So my question is, is the handler somehow paused, s开发者_Python百科top and restarted or is it something else. And do you have some suggestion like wake_lock. Thanks in advance, Simon

EDIT: Forgot to mention this is all running from a service


From time to time the gc runs to free up memory on your device. If running from the UI thread, your notification's updater might get collected as well.

I'm using a service for showing ongoing notifications, this way i can be sure, that neither the service nor the notification doesn't get stopped / collected.

The communication between my activities and the service i solved with handlers, but there are plenty of techniques for that too.


By default, the handler run in the same process of the UI thread, so I think you'd better use a service to update the progress bar. In this case, you want to update the UI for every 5 minute. You can use AlarmManager to start an alarm service to achieve this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜