安卓小部件在重启后无法显示

3

※这不是App2sd的问题。

(首先,您可以在Android市场上尝试此应用程序)

https://market.android.com/details?id=com.beadgrip.premierframe

这是一个图片框架小部件。小部件布局中有两个ImageView(2x2大小)。

1. 在主屏幕上添加小部件 -> 当然会出现!
2. 重新启动 -> 消失 (有时会出现...非常奇怪的问题...)
3. 但是,如果我旋转屏幕 -> 就会出现

这个问题发生在LG、三星、CM7 ROMs(和所有种类的“Home Launcher App”)以下的设备上。 但是,HTC Sense和MIUI没有问题。

更奇怪的事情是...

如果我删除小部件布局XML中的一个ImageView,则没有问题!
(或者不在provider.java源文件中的frame或picture bitmap之一设置setImageBitmap)

这是问题的内核源代码。

provider.java源代码

// Update Widget Method
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    PFramePhotoDatabase helper = new PFramePhotoDatabase(context);
    for (int appWidgetId : appWidgetIds) {
        int[] specificAppWidget = new int[] { appWidgetId };
        RemoteViews views = buildUpdate(context, appWidgetId, helper);
        appWidgetManager.updateAppWidget(specificAppWidget, views);
    }
    helper.close();
}

static RemoteViews buildUpdate(Context context, int appWidgetId, PFramePhotoDatabase helper) {
    RemoteViews views = null;
    // Getting a frame, picture from SQLite
    Bitmap bitmap_Pic = helper.getPhotoPicture(appWidgetId);
    Bitmap bitmap_Frm = helper.getPhotoFrame(appWidgetId);
    views = new RemoteViews(context.getPackageName(), R.layout.layout_widget22);

   // If I delete one 'if' it's not problem!, it's perfect!
   // So I devided buildUpdate Method as two kinds, But It's same problem :<
   if (bitmap_Pic != null) {
     views.setImageViewBitmap(R.id.wiv_Picture22, bitmap_Pic); // Picture set a ImageView
   }
   if (bitmap_Frm != null) {
    views.setImageViewBitmap(R.id.wiv_Frame22, bitmap_Frm);  // Frame set a ImageView
   }
   return views;
}
2个回答

1
你只需要在onReceive()方法中调用super.onReceive(),就可以防止小部件管理器生命周期的中断。

0

5
这是在没有提供任何额外信息的情况下粘贴链接的不良后果。由于链接现在已经失效,你应该简要解释一下答案。请注意不要改变原意。 - GoRoS

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接