I am developing a widget which is running without any errors but the ImageView
of my widget are not updating and also not giving any errors. Thus making me confused about what wrong i am doing. Here is the code:-
BroadcastReceiver _broadcastReceiver;
GetDrawableResources getDrawableResources = new GetDrawableResources();
private final SimpleDateFormat _sdfWatchTime = new SimpleDateFormat("HH:mm");
@Override
public void onEnabled(final Context context) {
super.onEnabled(context);
// TODO Auto-generated method stub
System.out.println("Entering onstart");
_broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context ctx, Intent intent) {
System.out.println("Registering BroadCast");
if (intent.getAction().compareTo(Intent.ACTION_TIME_TICK) == 0) {
System.out.println(_sdfWatchTime.format(new Date()));
Bundle extras = intent.getExtras();
if (extras != null) {
AppWidgetManager awm = AppWidgetManager
.getInstance(context);
ComponentName thisWidget = new ComponentName(
context.getPackageName(),
MainActivity.class.getName());
int[] appWidgetIds = awm.getAppWidgetIds(thisWidget);
onUpdate(context, awm, appWidgetIds);
}
}
}
};
context.getApplicationContext().registerReceiver(_broadcastReceiver,
new IntentFilter(Intent.ACTION_TIME_TICK));
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
for (int awID : appWidgetIds) {
updateAppWidget(context, appWidgetManager, awID);
}
}
private void updateAppWidget(Context context,
AppWidgetManager appWidgetManager, int awID2) {
// TODO Auto-generated method stub
// class to get drawable images that will be used to denote hours and
// minutes
int time[] = new int[new GetTime().getTime(context
.getApplicationContext()).length];
// class to get each digit of time separately eg 10:10, separating 1 0 1
// 0 working correctly
time = new GetTime().getTime(context.getApplicationContext());
// changing views
System.out.println("awID for " + awID2);
RemoteViews views = new RemoteViews(context
.getPackageName(), R.layout.activity_main);
views.setImageViewResource(R.id.ivHour0,
getDrawableResources.setTimeDrawable(time[0]));
views.setImageViewResource(R.id.ivHour1,
getDrawableResources.setTimeDrawable(time[1]));
views.setImageViewResource(R.id.ivMinute0,
getDrawableResources.setTimeDrawable(time[2]));
views.setImageViewResource(R.id.ivMinute1,
getDrawableResources.setTimeDrawable(time[3]));
System.out.println("updating the views");
appWidgetManager.updateAppWidget(awID2, views);
}
The output in my LogCat
06-28 19:46:00.076: I/System.out(680): Registering BroadCast
06-28 19:46:00.086: I/System.out(680): 19:46
06-28 19:46:00.096: I/System.out(680): awID for 14
06-28 19:46:00.096: I/System.out(680): updating the views
06-28 19:47:00.086: I/System.out(680): Registering BroadCast
06-28 19:47:00.086: I/System.out(680): 19:47
06-28 19:47:00.096: I/System.out(680): awID for 14
06-28 19:47:00.096: I/System.out(680): updating the views
Thus the appWidgetID is correct and the function is executing as it should but the Views are not updating. They are same as before.