Android 无法从包中检索数据
我正在尝试检索我添加到捆绑包中的一些数据,但无法使用正常的方式进行检索 我目前的代码是Android 无法从包中检索数据,android,Android,我正在尝试检索我添加到捆绑包中的一些数据,但无法使用正常的方式进行检索 我目前的代码是 Intent i = getIntent(); Bundle bundle = i.getExtras(); for (String key : bundle.keySet()) { Object value = "start_color"; start_color = String.format("%s", key);
Intent i = getIntent();
Bundle bundle = i.getExtras();
for (String key : bundle.keySet()) {
Object value = "start_color";
start_color = String.format("%s", key);
}
这会得到bundle值,但是当我使用这样的标准代码时
Intent i = getIntent();
Bundle bundle = i.getExtras();
if (bundle != null)
{
String value = bundle.getString("start_color");
}
无法获取捆绑包的值我不明白为什么会发生这种情况!!有人能告诉我为什么会这样吗
这是我将值放入包中的代码
String rgbString = "R: " + Color.red(color) + " B: " + Color.blue(color) + " G: " + Color.green(color);
//Change activity send data
Intent device = new Intent(v.getContext(), Create_Preset.class);
device.putExtra(rgbString,"start_color");
startActivity(device);
overridePendingTransition(R.anim.left_in, R.anim.left_out);
我甚至通过RESTAPI使用修改过的代码将新行添加到我的预设表中,所以那些想知道捆绑包是否有价值的人,是的,它有
这是我正在存储的数据库上的选择值,请参见start\u color
和end\u color
这些是我从包中获取的值
您需要使用迭代器接口以bundle的形式从键集获取值。键集返回一组字符串。 例如
Set keys=bundle.keySet();
迭代器itr=keys.Iterator();
while(itr.hasNext()){
String key=itr.next();
字符串值=bundle.get(键);
}
您正在将值添加为键,并将键添加为值
正确:
Intent.putExtra(键、值)
你所拥有的:
device.putExtra(rgbString,“开始颜色”) 您确定捆绑包包含该值吗?显示将值放入bundle@Marcus捆绑包包含值,否则我如何用修改过的代码获取它?您正在反转键和值。这是不正确的,不相关的。foreach循环适用于所有
Iterable
实现。
Host: localhost
Database: led
Generation Time: Jan 17, 2015 at 04:37 PM
Generated by: phpMyAdmin 4.2.7.1 / MySQL 5.6.20
SQL query: SELECT * FROM `preset` WHERE 1 LIMIT 0, 25 ;
Rows: 2
Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available.
preset starttime_hour starttime_min endtime_hour endtime_min startColor endColor
test 12 0 12 0 R: 159 B: 159 G: 159 R: 159 B: 159 G: 159
test2 12 0 12 0 R: 39 B: 122 G: 91 R: 39 B: 122 G: 91
Set<String> keys = bundle.keySet();
Iterator<String> itr = keys.iterator();
while(itr.hasNext()) {
String key = itr.next();
String value = bundle.get(key);
}