2017-05-26 32 views
0

我有一個配置活動的小部件。「添加小部件」按鈕啓動應用程序,而不是更新小部件

當應用程序未啓動,我通過小部件菜單添加小部件 - 「添加小部件」按鈕工作正常。

當應用程序啓動時,但標籤(可在方形按鈕菜單中啓動的應用程序中找到)添加按鈕調用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(); 
    } 
}; 

回答

0

解決

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