1.updatePeriodMillis不执行
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="294dp" android:minHeight="72dp" android:updatePeriodMillis="86400000" android:previewImage="@drawable/preview" android:initialLayout="@layout/example_appwidget" android:configure="com.example.android.ExampleAppWidgetConfigure" android:resizeMode="horizontal|vertical"> </appwidget-provider>其中android:updatePeriodMillis的作用是设置更新频率, 单位是毫秒, 在实际使用中我用1000测试了一下,发现不执行。
public int updatePeriodMillis Since: API Level 3 How often, in milliseconds, that this AppWidget wants to be updated. The AppWidget manager may place a limit on how often a AppWidget is updated. This field corresponds to the android:updatePeriodMillis attribute in the AppWidget meta-data file. Note: Updates requested with updatePeriodMillis will not be delivered more than once every 30 minutes.
查看了一下官方文档才知道, 要30分钟以上才行。 如果要执行30分钟以下频率的或者允许用户自己定义的,建议还是使用AlarmManager吧,此时可以将 android:updatePeriodMillis设置为0。
2. 在Android4.0系统中onEnabled、onDisabled不执行
onEnabled:第一个组建创建时调用
onDisabled:最后一个组建删除时调用
在2.1, 2.2, 2.3, ,2.3.3, 4.0.4平台上进行了测试, 在4.0.4平台上,创建第一个组建不会调用onEnabled,删除最后一个组建也不会调用onDisabled,只会调用OnUpdate; 其他平台正常!
3. 顺便说一下Widget预览图的设置(3.0以上才支持):
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" ... android:previewImage="@drawable/preview"> </appwidget-provider>
属性列表对比:
(2.1) (4.0)