Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \widget configuration activity.
public class WidgetConfigure extends Activity {
private int widgetID;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("Lifecycle", "WidgetConfigure.onCreate");
setContentView(R.layout.widget_configure);
widgetID = this.getIntent().getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
setResult(RESULT_CANCELED, new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetID));
}
public void onButtonClicked(View view) {
Log.v("Lifecycle", "WidgetConfigure.onButtonClicked");
if (((RadioButton) this.findViewById(RefreshStrategy.SYSTEM)).isChecked()) {
WidgetProvider.configure(widgetID, true);
} else if (((RadioButton) this.findViewById(RefreshStrategy.USER)).isChecked()) {
WidgetProvider.configure(widgetID, false);
}
setResult(RESULT_OK, new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetID));
finish();
}
}
理论上RESULT_OK
应该在活动中按下按钮后发送,RESULT_CANCELED
在任何其他情况下,但在按下设备上的物理按钮 HOME 时不会发生。
任何想法如何解决这个问题?