onReceive에 대한 질문인데요
intent로 action을 받았습니다 action에 대한 명령을 수행했는데
그 다음에 위젯을 어떻게 업데이트 시키나요?
그리고 위젯 디버깅 할때 디버깅이 자꾸 종료가 되네요..
해결방법좀 알려주세요 ㅎ
업데이트를 해도 자꾸 적용이 안되네요.. 소스 코드는
public class Widget extends AppWidgetProvider {
private DataBase awcAdapter;
private Cursor cursor;
RemoteViews views;
private static final String WIDGET_NEXT_ACTION = "com.AWC.widget.next";
private static final String WIDGET_ALBUM_ACTION = "com.AWC.widget.album";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onReceive(context, intent);
awcAdapter = new DataBase(context);
String action = intent.getAction();
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
if(action.equalsIgnoreCase(WIDGET_NEXT_ACTION)){
awcAdapter.open();
cursor = awcAdapter.fetchAllRows();
cursor.moveToNext();
String uri = cursor.getString(2);
Uri cast_uri = Uri.parse(uri);
BitmapFactory.Options bfo = new BitmapFactory.Options();
bfo.inSampleSize = 4;
views.setImageViewUri(R.id.widget_image, cast_uri);
awcAdapter.close();
appWidgetManager.updateAppWidget(new ComponentName(context.getPackageName(), "com.AWC.Widget"), views);
return;
}
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
final int N = appWidgetIds.length;
awcAdapter = new DataBase(context);
// Perform this loop procedure for each App Widget
// that belongs to this provider
RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.widget_layout);
PendingIntent next = PendingIntent.getService(context, 0, new Intent(WIDGET_NEXT_ACTION),
PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent image = PendingIntent.getBroadcast(context, 0, new Intent(WIDGET_ALBUM_ACTION),
PendingIntent.FLAG_UPDATE_CURRENT);
awcAdapter.open();
cursor = awcAdapter.fetchAllRows();
cursor.moveToFirst();
BitmapFactory.Options bfo = new BitmapFactory.Options();
bfo.inSampleSize = 4;
String uri = cursor.getString(2);
Uri result = Uri.parse(uri);
views.setImageViewUri(R.id.widget_image, result);
cursor.moveToNext();
awcAdapter.close();
views.setOnClickPendingIntent(R.id.next, next);
views.setOnClickPendingIntent(R.id.widget_image, image);
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}



