开发者

UI update on widget stops after a few hours with no error or exception

I created a widget that uses a service with wakelock to update and parse data from an xml and update the widget's UI so that items would "rotate every few seconds (standard news feed widget).

The problem is that the UI stops updating after a few hours although the data keeps updating.

Here's the code I am using to update the UI:

mUpdateTimeTask = null;
mUpdateTimeTask = new Runnable() 
{
    public void run() 
    {
        if(which_item+1 < Widget_titles.length)
            which_item++;
        else
            which_item = 0;

        if(Widget_which_item_ed != null)
        {
           Widget_which_item_ed.putInt("WIDGET_WHICH_ITEM", which_item);
           Widget_which_item_ed.commit();   
        }
   开发者_C百科     else
        {
           Widget_which_item = context.getSharedPreferences("WIDGET_WHICH_ITEM", Context.MODE_WORLD_WRITEABLE); 
           Widget_which_item_ed = Widget_which_item.edit();

           Widget_which_item_ed.putInt("WIDGET_WHICH_ITEM", which_item);
           Widget_which_item_ed.commit();   
        }


        updateViews.setTextViewText(R.id.WidgetText, Widget_titles[which_item]); 
        updateViews.setTextViewText(R.id.WidgetPostTime, rightNow.get(Calendar.MONTH)+"/"+rightNow.get(Calendar.DATE)+"/"+rightNow.get(Calendar.YEAR));
        manager = AppWidgetManager.getInstance(context);
        manager.updateAppWidget(WidgetId, updateViews); 

        mHandler.removeCallbacks(mUpdateTimeTask);
        mHandler.postDelayed(this, widget_interval * 1000);
    }
};

mHandler.postDelayed(mUpdateTimeTask, widget_interval * 1000);
Log.i(TAG, "sliding update handler was configed");

I am really stuck and could really use help.

Edit:

i managed to go around this problem by implementing the BroadCastReciever for the screen on/off intents as shown in a tutorial here: http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/ and therefore the amount of time that the widget needs to run is much smaller.


Edit:

i managed to go around this problem by implementing the BroadCastReciever for the screen on/off intents as shown in a tutorial here: http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/ and therefore the amount of time that the widget needs to run is much smaller.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜