title: AppWidget - Configurable widget not found but find id (when canceled)
body: <p>I'm using an Activity to let user configure their widget when they put to launcher, contains two buttons to apply config and cancel. After widget dropped, it launches automatically by launcher.</p>
  <hr />
  <p><strong>My issue</strong></p>
  <p>when <em><strong>&quot;recent task&quot; or &quot;home&quot; button was pressed (or gesture navigation swiped)</strong></em> in configuration Activity, the Activity will be finished, this <strong>widget not found in launcher but in <code>AppWidgetManager.getAppWidgetIds()</code></strong>, <strong>and can still be refreshed even they are invisible in launcher</strong>.</p>
  <p>There's <strong>no such problem if presses back button or button in app</strong>. <em>The expected result is configuration Activity and widget both gone if configuration was canceled.</em></p>
  <hr />
  <p>I think this problem may not cause by my code but by the launcher, I tested with MIUI system launcher and Microsoft launcher, they have the same problem, but the difference is, Microsoft launcher refresh soon after the Activity finish, but MIUI refresh after long time (or even not)</p>
  <p>My purpose is to let user can first configure their widget, <strong>and can be able to reconfigure them by long press the widgets (if the launcher supports)</strong>.</p>
  <p>My current solution is remove the <code>android:configure=&quot;com.xxx.WidgetSettingsActivity&quot;</code> and <code>android:widgetFeatures=&quot;reconfigurable&quot;</code> attributes in  <code>&lt;appwidget-provider&gt;</code> xml (see xml code block below), but it may be difficult for users to reconfigure widgets because they need to manually find the configuration page and the widget they want to modify the configuration (if the launcher supports multiple widget instances)</p>
  <hr />
  <p>by developer guide, my configuration Activity like below:</p>
  <pre class="lang-java prettyprint-override"><code>//onCreate method
  //get target id
      Intent intent = getIntent();
      int appWidgetId = extras.getInt(
          AppWidgetManager.EXTRA_APPWIDGET_ID,//&quot;appWidgetId&quot;
          AppWidgetManager.INVALID_APPWIDGET_ID//0
      );
  
  //default when user not press ok button
  //this widget will not be placed
      setResult(RESULT_CANCELED/*0*/, new Intent()
          .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
              appWidgetId
          )
      );
  
  //ok onClick method
  //when user pressed ok button
  //update widget and finish
  //WidgetProvider will receive this broadcast then do update
      sendBroadcast(new Intent()
          .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,//&quot;appWidgetIds&quot;
              new int[]{appWidgetId}
          )
      );
  //result ok to launcher then launcher will display it
      setResult(RESULT_OK/*-1*/, new Intent()
          .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
               appWidgetId
          )
      );
      finish();
  
  //when user pressed back button
  //in NavigationBar or ActionBar
      finish();
  
  </code></pre>
  <p>and Activity for view and reconfigure placed widgets:</p>
  <pre class="lang-java prettyprint-override"><code>//onCreate method
  //get ids from AppWidgetManager
      AppWidgetManager awm = (AppWidgetManager) getSystemService(
          Context.APPWIDGET_SERVICE//&quot;appwidget&quot;
      );
      int[] ids = awm.getAppWidgetIds(
          new ComponentName(...)/*Widget Provider ComponentName*/
      );
  
  //do adapter
  //Click adapter item to enter configuration page
  </code></pre>
  <p>activity and widget in manifest</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;!--application--&gt;
      &lt;activity
          ...
          android:name=&quot;com.xxx.WidgetSettingsActivity&quot;
          ...
              &gt;
          &lt;intent-filter&gt;
              &lt;action
                  android:name=&quot;android.appwidget.action.APPWIDGET_CONFIGURE&quot; /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;receiver
          android:name=&quot;com.xxx.WidgetProvider&quot;
          ...
              &gt;
          &lt;intent-filter&gt;
              &lt;action
                  android:name=&quot;android.appwidget.action.APPWIDGET_UPDATE&quot; /&gt;
              &lt;action
                  android:name=&quot;android.appwidget.action.APPWIDGET_ENABLED&quot; /&gt;
              &lt;action
                  android:name=&quot;android.appwidget.action.APPWIDGET_DISABLED&quot; /&gt;
              &lt;action
                  android:name=&quot;android.appwidget.action.APPWIDGET_DELETED&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;meta-data
              android:name=&quot;android.appwidget.provider&quot;
              android:resource=&quot;@xml/widget_provider_info&quot; /&gt;
      &lt;/receiver&gt;
  </code></pre>
  <p>WidgetProviderInfo.xml config</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;appwidget-provider xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      ...
      android:configure=&quot;com.xxx.WidgetSettingsActivity&quot;
      android:widgetFeatures=&quot;reconfigurable&quot;
      ...
          /&gt;
  
  </code></pre>
  <hr />
  <p>I tried <code>AppWidgetHost.deleteAppWidgetId(Context, appWidgetId)</code> in the answer to another question but is doesn't work.</p>
  <p>How can I remove these invisible widgets by code or make launcher refresh?
  <br>Does anyone know how to resolve?<br> Thanks</p>