[Android Software Development] killersnowman:
i made some edits and ran into a problem where my intent was caught be onReive() but the local variable called count never incremented... this is crazy! a block of code that would execute whenever a particular intent was recieved never did what i wanted:

count++;

refreshWidgets();

Toast.makeText(.... some indication this was done ...);

the toast was always displayed but the count never incremented. i thought the refreshWidgets method was bunk so i manually set the count in the method... everything was good... then i make a toast after the count++ to display count. count never incremented. well after messing around i found that i had count as a

private int count

i changed it to a

private static int count

and it worked! weird...

this is my final code that makes a number on a widget increment every couple of seconds. note: setting a repeating alarm with the AlarmManager for a small amount of time did not work. i had to make a nested one time alarm that kept rearming itself. and i got rid of the service cause some of the debuging tools in cm7 said it never started. cross that bridge when i get there....

package com.tsb.gmailinboxtextcloud;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
import android.widget.Toast;

public class GITextCloud extends AppWidgetProvider {
private static int count = 0;
private static int widgetCount = 0;
public static final String INCREMENT_COUNT_UPDATE = "INCREMENT_COUNT_UPDATE";

@Override
public void onEnabled(Context context) {
super.onEnabled(context);
count = 0;
setOneTimeAlarm(this.getClass(), context);
}

@Override
public void onDisabled(Context context) {
super.onDisabled(context);
}

@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (intent.getAction().equals("android.appwidget.action.APPWIDGET_ENABLED")) {
} else if (intent.getAction().equals("android.appwidget.action.APPWIDGET_DISABLED")) {
} else if (intent.getAction().equals(INCREMENT_COUNT_UPDATE)) {
count++;
refreshViews(context);
Toast.makeText(context, "widget #" + widgetCount, Toast.LENGTH_SHORT).show();
if (widgetCount != 0) {
setOneTimeAlarm(this.getClass(), context);
}
} else {
//Toast.makeText(context, "count = " + count + " | " + intent.getAction(), Toast.LENGTH_LONG).show();
}
}

/** Called when the activity is first created. */
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
//super.onUpdate(context, appWidgetManager, appWidgetIds);
}

private void refreshViews(Context context) {
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.main);
rv.setTextViewText(R.id.widget_textview, "" + count);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
ComponentName cName = new ComponentName(context, GITextCloud.class);
widgetCount = manager.getAppWidgetIds(cName).length;
manager.updateAppWidget(cName, rv);
}

private void setOneTimeAlarm(java.lang.Class<?> cls, Context context) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, cls);
intent.setAction(INCREMENT_COUNT_UPDATE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (3 * 1000), pendingIntent);
}

}