[Anroid Widget]问题集锦

来源:互联网 发布:mac常用免费软件 编辑:程序博客网 时间:2024/06/02 01:10

1. updatePeriodMillis不执行

[html] view plaincopyprint?
  1. <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:minWidth="294dp"  
  3.     android:minHeight="72dp"  
  4.     android:updatePeriodMillis="86400000"  
  5.     android:previewImage="@drawable/preview"  
  6.     android:initialLayout="@layout/example_appwidget"  
  7.     android:configure="com.example.android.ExampleAppWidgetConfigure"   
  8.     android:resizeMode="horizontal|vertical">  
  9. </appwidget-provider>  


其中android:updatePeriodMillis的作用是设置更新频率, 单位是毫秒, 在实际使用中我用1000测试了一下,发现不执行。

[html] view plaincopyprint?
  1. public int updatePeriodMillis  
  2.   
  3. Since: API Level 3  
  4. 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.  
  5. This field corresponds to the android:updatePeriodMillis attribute in the AppWidget meta-data file.  
  6. <strong>Note: Updates requested with updatePeriodMillis will not be delivered more than once every 30 minutes.</strong>  

查看了一下官方文档才知道, 要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以上才支持):

[html] view plaincopyprint?
  1. <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"  
  2.   ...  
  3.   android:previewImage="@drawable/preview">  
  4. </appwidget-provider>  


属性列表对比:

                                

(2.1) (4.0)


原创粉丝点击