Note that there are some explanatory texts on larger screens.

plurals
  1. POGet widget id from BroadcastReceiver
    text
    copied!<p>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</p> <p>Configure activity:</p> <pre><code>resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetId); setResult(RESULT_CANCELED, resultValue); listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { ... resultValue.putExtra("mykey", "otherinfo"); setResult(RESULT_OK, resultValue); finish(); } }); </code></pre> <p>AppWidgetProvider:</p> <pre><code>@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) // &lt;-- 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); } </code></pre> <p>BroadCastReceiver:</p> <pre><code>public void onReceive(Context context, Intent intent) { intent.getStringExtra(AppWidgetManager.EXTRA_APPWIDGET_ID); // &lt;-- NULL .. } </code></pre> <p>getStringExtra returns always null values... maybe the code above is completely wrong</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload