【问题标题】:"add widget" button starts app instead of updating widget“添加小部件”按钮启动应用程序而不是更新小部件
【发布时间】: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();
    }
};

【问题讨论】:

    标签: android widget


    【解决方案1】:

    已解决: 在完成()之后添加该代码:

     Intent startMain = new Intent(Intent.ACTION_MAIN);
            startMain.addCategory(Intent.CATEGORY_HOME);
            startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(startMain);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-27
      • 2020-01-07
      • 2020-02-22
      相关资源
      最近更新 更多