首页 新闻 会员 周边 捐助

关于BroadcastReceiver向Activity传值的问题

0
悬赏园豆:15 [待解决问题]
    private void RefreshWidget(DataSourceObject result) {
Intent intent = new Intent(context, activity_main.class); String str = result != null ? String.valueOf(result.getid()) : "0"; intent.putExtra("xmlKeyByWidgetProvider", str); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); RemoteViews myRemoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); myRemoteViews.setOnClickPendingIntent(R.id.widgetLayout, pendingIntent); myRemoteViews.setTextViewText(R.id.widgetEnText, result.getdatasource_En()); myRemoteViews.setTextViewText(R.id.widgetCnText, result.getdatasource_Cn()); ComponentName mComponentName = new ComponentName(context, WidgetProvider.class); AppWidgetManager myAppWidgetManager = AppWidgetManager .getInstance(context); myAppWidgetManager.updateAppWidget(mComponentName, myRemoteViews); }

这是我在BroadcastReceiver里面刷新AppWidgetManager的代码,在Activity里面我写了这样的代码用于获取值。
@Override

protected void onResume() {
    super.onResume();

    Intent intent = this.getIntent();
    if (intent == null)
        return;

    if (intent.hasExtra("xmlKeyByWidgetProvider")) {
        String str = intent.getStringExtra("xmlKeyByWidgetProvider");
        Log.i("ssss", str);
        gallery.setSelection(Integer.parseInt(str));
    }

}

但是Intent并没有获取到AppWidgetManager传过来的值。

jia_vip的主页 jia_vip | 初学一级 | 园豆:5
提问于:2013-04-06 00:56
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册