2017-05-26 34 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);