I need to know the widget id inside onReceive(). I thought to associate the selected item informations of the configure activity to the new widget id, and then save them to sharedpreferences so that i can know what to do inside onReiceive() by reading from sharedpreferences
Configure activity:
resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetId);
setResult(RESULT_CANCELED, resultValue);
listView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
...
resultValue.putExtra("mykey", "otherinfo");
setResult(RESULT_OK, resultValue);
finish();
}
});
AppWidgetProvider:
@Override
public void onEnabled(Context context)
{
super.onEnabled(context);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
int id = intent.getStringExtra(AppWidgetManager.EXTRA_APPWIDGET_ID) // <-- THIS IS NULL!
// save id on shared preferences
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
am.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis(), UPDATE_INTERVAL, pi);
}
BroadCastReceiver:
public void onReceive(Context context, Intent intent)
{
intent.getStringExtra(AppWidgetManager.EXTRA_APPWIDGET_ID); // <-- NULL
..
}
getStringExtra returns always null values... maybe the code above is completely wrong