Android 将意图从广播接收器传递给活动
我在broadcast Receiver类中检索到了呼叫日志数据(号码、类型、日期、持续时间)。现在我想将该数据设置到activity类的列表视图中。我无法获得如何在这两个活动之间通过intent发送数据,并将其设置到列表视图中 要在活动类中调用的代码:Android 将意图从广播接收器传递给活动,android,android-intent,android-activity,broadcastreceiver,Android,Android Intent,Android Activity,Broadcastreceiver,我在broadcast Receiver类中检索到了呼叫日志数据(号码、类型、日期、持续时间)。现在我想将该数据设置到activity类的列表视图中。我无法获得如何在这两个活动之间通过intent发送数据,并将其设置到列表视图中 要在活动类中调用的代码: String number = cursor.getString(cursor.getColumnIndex("address")); // check for null String date
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 i=new Intent();
i.putExtra(number,number);
i.putExtra(date, date);
i.putExtra(message_text, message_text);
i.putExtra(type,type);
context.sendBroadcast(i);
您可以通过两种方式完成您的工作,首先使用
static public
和broadcastReceiver
在列表调用context.adapter.notifyDataSetChange()中设置数据后定义适配器代码>并且不需要将数据从intent传递到类
第二种方法是在你想要更新列表的类中编写一个接收器,然后在broadcastReceiver
中发送另一个Broadcast
。并在接收器中更新您的列表
我希望这对你有用你在broadcastReceiver
中调用新活动了吗?把你的一些示例工作代码放进去没有,我不知道在broadcastReceiver类中调用新活动。我是android新手,请你帮我做一下。我已经编辑了我的代码先生,我必须将检索到的数据从广播接收器类发送到Activity类,并设置到Activity classprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.Activity_main);ListView lv=(ListView)findViewById(R.id.listView1)中的列表视图中;