android widget和activity通信多信号传递
时间:2010-11-30 来源:fly123456789
widget中updateAppWidget的代码:
Intent intentSearch = new Intent(context, Accounts.class);
intentSearch.setAction("searchFlag");
PendingIntent pendingIntentSearch = PendingIntent.getActivity(context, 0,intentSearch, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.search_mail_widget_button_bg, pendingIntentSearch);
Intent intentAccountSet = new Intent(context, Accounts.class);
intentAccountSet.putExtra("accountSetFlag", true);
intentAccountSet.setAction("accountSetFlag");
PendingIntent pendingIntentAccountSet = PendingIntent.getActivity(context, 0,intentAccountSet, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.account_set_mail_widget_button_bg, pendingIntentAccountSet)
注意:多个信号通信时,一定要使intentSearch.setAction;一定要使参PendingIntent.FLAG_UPDATE_CURRENT,否activity那边接收不到传过来的信号。
在activity的OnCreat中添加接收信号代如:
if(action.equals("searchFlag"))
{
// Log.i(K9.LOG_TAG, "####### hjf debug searchFlag #####");
searchFlag = (boolean)intent.getBooleanExtra("searchFlag", false);
}
if(action.equals("accountSetFlag"))
{
// Log.i(K9.LOG_TAG, "####### hjf debug accountSetFlag #####");
accountSetFlag = (boolean)intent.getBooleanExtra("accountSetFlag", false);
}
相关阅读 更多 +