Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I force an update in a configuration activity?
    primarykey
    data
    text
    <p>I'm writing a widget with a configuration activity which calls the following method when its <code>OK</code> button is clicked:</p> <pre><code>private void ok() { // ...Do Widget Configuration... // Force an update Context context = getApplicationContext(); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); AppWidgetManager.getInstance(context).updateAppWidget(widget_id, views); // Return the expected result Intent result = new Intent(); result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widget_id); setResult(RESULT_OK, result); finish(); } </code></pre> <p>This is almost verbatim from <a href="http://developer.android.com/guide/topics/appwidgets/index.html#Configuring" rel="noreferrer">the documentation</a>. <code>widget_id</code> holds the widget ID that was dug up during the activity's <code>onCreate()</code>.</p> <p>When I place an instance of the widget on the home screen, I've verified that I get the expected sequence of events:</p> <ul> <li><code>onReceive()</code> gets an <code>ACTION_APPWIDGET_ENABLED</code> if it's the first one.</li> <li><code>onUpdate()</code> gets called (in which I detect that the widget isn't configured and draw something as a default action).</li> <li>The configuration activity appears.</li> <li>When I press <code>OK</code>, the <code>ok()</code> method above gets called.</li> </ul> <p>The method gets all the way through to the <code>finish()</code> and the configuration activity goes away, but there's no call to <code>onUpdate()</code> or <code>onReceive()</code> after this point. (The widget itself has no <code>updatePeriodMillis</code>.) I end up with a widget on the screen that has the results of my default action but never gets updated.</p> <p>If I set the widget up without a configuration activity, it gets updated when created and everything works as expected (just without the configured bits).</p> <p>Am I missing something in the way I force an update?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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