开发者

Trying to update my widget with no result

开发者 https://www.devze.com 2023-01-18 20:47 出处:网络
I am trying to create my first widget. To make a experiment I am trying to visualize a Toast every update but it does not appear.

I am trying to create my first widget. To make a experiment I am trying to visualize a Toast every update but it does not appear.

This is my manifest:

开发者_运维知识库
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.skatephone.smokecounter"
  android:versionCode="1"
  android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <receiver android:name=".SmokeCounter" >
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            <action android:name="com.skatephone.smokecounter.SmokeCounter.ACTION_WIDGET_RECEIVER"/>
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
                   android:resource="@xml/smoke_widget_info" />
    </receiver>
</application>
<uses-sdk android:minSdkVersion="4" />

And in the onUpdate method of my AppWidgetProvider class I inserted:

Toast.makeText(context, "onUpdate", Toast.LENGTH_SHORT).show();
appWidgetManager.updateAppWidget(appWidgetIds, views);

It seems that it doesn't update, should do it every 5 seconds!

Any idea?


I resolved with a Timer:

Timer timer = new Timer();
timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 10000); // Every 10 seconds
0

精彩评论

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

关注公众号