【问题标题】:pass Intent from BroadcastReceiver to Activity将 Intent 从 BroadcastReceiver 传递给 Activity
【发布时间】:2013-12-04 07:26:17
【问题描述】:

我已在广播接收器类中检索到呼叫日志数据(号码、类型、日期、持续时间)。现在我想将该数据设置到活动类的列表视图中。我无法了解如何通过这些之间的意图发送数据两个活动并设置为列表视图。

在活动类中调用的代码:

String number = cursor.getString(cursor.getColumnIndex("address")); // check for null
                        String date = cursor.getString(cursor.getColumnIndex("date")); // convert to date its long
                        String message_text = cursor.getString(cursor.getColumnIndex("body"));
                        String type = cursor.getString(cursor.getColumnIndex("type")); // check type and get names

                        // send email from here
                        sendSMSEmail(number, date, message_text, type);
                    }
                }
                cursor.close();
                String finalData=number+"\n"+date+"\n"+message_text+"\n"+type;

我也通过了 Intent

Intent i=new Intent();
        i.putExtra(number,number);
        i.putExtra(date, date);
        i.putExtra(message_text, message_text);
        i.putExtra(type,type);
        context.sendBroadcast(i);

【问题讨论】:

  • 你在BroadcastReciver中调用了新活动吗?
  • 放一些你的示例工作代码
  • 不,我不知道在 broadcastReceiver 类中调用新活动。我是 android 新手,请你帮我做。
  • 我已经编辑了我的代码

标签: android android-intent android-activity broadcastreceiver


【解决方案1】:

你可以用两种方式完成你的工作,首先用static publicBroadcastReciver定义你的适配器,然后将数据设置为列表调用context.adapter.notifyDataSetChange();,并且不需要将数据从意图传递给你的类

您可以采用的第二种方法是在班级中编写一个您想要更新列表的接收器,然后在BroadcastReciver 中发送另一个Broadcast 到该接收器。并在接收器中更新您的列表。

希望对你有用

【讨论】:

  • 先生,我必须将检索到的数据从广播接收器类发送到 Activity 类,并设置到 Activity 中存在的列表视图 classprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView lv=(ListView)findViewById(R.id.listView1);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-14
  • 2012-09-02
相关资源
最近更新 更多