【发布时间】:2011-05-02 10:12:36
【问题描述】:
我的应用是一个小部件,它的背景是一个 imageView。 在 WidgetProvider 的 onUpdate() 方法中,我将来自 sdcard 的位图放入这个 imageView 中调用这个方法:
public static void changeSkinWidget(Context context,String imageBackgroundPath) throws IOException{
RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.widget);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Log.i(Constants.DebugTag,"changeSkinWidget receive new path " +imageBackgroundPath);
//Change Background Skin :
FileInputStream is;
try {
is = new FileInputStream(new File(imageBackgroundPath
+ "background.png"));
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(is);
views.setImageViewBitmap(R.id.ImageBackground01, bm);
ComponentName thisWidget = new ComponentName(context,
MyWidget.class);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(thisWidget, views);
bis.close();
is.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
问题是我总是挂载/卸载 SDCARD,小部件丢失了这个位图,并且 ImageView 获得了在布局声明 (src=R.drawable.defaultbackground) 中找到的默认可绘制对象,并且似乎我的小部件已重新加载。 为了跟踪这一点,我使用了 onReceive() 方法: Log.i(Constants.DEBUG_TAG,"接收意图:"+intent.getAction()); 但是logcat中什么都没有出现......我预计可能是ACTION_APPWIDGET_UPDATE的意图 行动,但什么都没有。
我也曾尝试将 recycle() 调用到我的位图...这并不能解决问题。
在挂载/卸载时查看 logcat 没有任何奇怪的错误...
任何帮助将不胜感激! 克里斯托夫。
【问题讨论】:
标签: android bitmap android-widget widget sd-card