生命周期:
onEnable(第一次添加时调用)---onUpdate(每添加一个都会调用)-----onDeleted(每删除一个都会调用,包括最后一个)-----onDisabled(全部删除时才会调用)
//onReceive 来自广播,因为widget本身就是使用的广播机制
在生命周期开始前,都会向系统发送以下对应的广播。
action: android.appwidget.action.APPWIDGET_ENABLED
action: android.appwidget.action.APPWIDGET_UPDATE
android.appwidget.action.APPWIDGET_DELETED
android.appwidget.action.APPWIDGET_DISABLED
!!! FAILED BINDER TRANSACTION !!!问题解决方案:
1.让美工将图片做小
2.设置图片时,可以换做setURL/setInt
3.BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = 2;
//
If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory. The sample size is the number of pixels in either dimension that correspond to a single pixel in the decoded bitmap. For example, inSampleSize == 4 returns an image that is 1/4 the width/height of the original, and 1/16 the number of pixels. Any value <= 1 is treated the same as 1. Note: the decoder will try to fulfill this request, but the resulting bitmap may have different dimensions that precisely what has been requested. Also, powers of 2 are often faster/easier for the decoder to honor.
4. 每次更新的时候 都需要new RemoteViews。 (ComponentName AppWidgetManager不需要每次都new)
widget居中的问题,
屏幕一般都是4x4的, 一个格子的大小为72dpx72dp