【发布时间】:2017-05-26 20:28:02
【问题描述】:
我有一个带有配置活动的小部件。
当应用程序未启动并且我正在通过小部件菜单添加小部件时 - “添加小部件”按钮可以正常工作。
当应用程序启动时,但选项卡式(可以在方形按钮菜单中的启动应用程序中找到)添加按钮调用 MainActivity。
这里是添加按钮点击的代码:
View.OnClickListener mOnClickListener = new View.OnClickListener() {
public void onClick(View v) {
System.out.println("ACTIVITY mOnClickListener");
//final Context context = RatesWidgetConfigureActivity.this;
SharedPreferences.Editor editor = getSharedPreferences(ConfigData.WIDGET_SHARED_PREF_NAME, MODE_PRIVATE).edit();
editor.putString("widget_currency_1", spCurrencyFirst.getSelectedItem().toString());
editor.putString("widget_currency_2", spCurrencySecond.getSelectedItem().toString());
editor.putString("widget_currency_3", spCurrencyThird.getSelectedItem().toString());
editor.commit();
// It is the responsibility of the configuration activity to update the app widget
InAppProperties.getInstance().LoadingRates = true;
RatesWidget.isRefresh = true;
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
RatesWidget.updateAppWidget(getApplicationContext(), appWidgetManager, mAppWidgetId);
// Make sure we pass back the original appWidgetId
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}
};
【问题讨论】: