我正在设置resultActivty。我必须取回结果,所以我正在做类似的事情
我已经尝试过,但是在这里我只得到不值的键
Intent i = new Intent(this, CustImageSignatureUploadFragment.class);
i.putExtra("uniqueBiometric", uniqueBiometricList);
setResult(RESULT_OK, i);
finish();
else if (requestCode == File_Key.BIOMETRICUNIQUE) {
uniqueBiometricList = (HashMap<String,
CommKycUpload>)data.getSerializableExtra("uniqueBiometric");
CommKycUpload is my pojo which is implementing parcelable
答案 0 :(得分:0)
您可以尝试使用此方法来填充意图:
val map = HashMap<String,YourObject>()
val intent = Intent()
intent.putExtra("SIZE", map.size)
for (k in 0..map.size) {
intent.putExtra("KEY"+k, map.keys.toList()[k])
intent.putExtra("VALUE"+k, map[map.keys.toList()[k]])
}
这是为了读回它:
val mapReceived = hashMapOf<String,YourObject>()
val intReceived = getIntent()
if (intReceived.hasExtra("SIZE")) {
val size = intReceived.getIntExtra("SIZE", 0)
for (k in 0..size) {
mapReceived[intReceived.getStringExtra("KEY"+k)] = intReceived.getParcelableExtra("VALUE"+k)
}
}
可能不是最聪明的,但应该可以工作
在Java中:
写作:
HashMap<String, ActivityBase> map = new HashMap<String,ActivityBase>();
Intent intent = new Intent();
intent.putExtra("SIZE", map.size());
for (int k=0; k<=map.size(); k++){
intent.putExtra("KEY"+k, (String)map.keySet().toArray()[k]);
intent.putExtra("VALUE"+k, (ActivityBase) map.get(map.values().toArray()[k]));
}
阅读:
HashMap<String, ActivityBase> mapReceived = new HashMap<String,ActivityBase>();
Intent intReceived = getIntent();
if (intReceived.hasExtra("SIZE")) {
int size = intReceived.getIntExtra("SIZE", 0);
for (int k=0; k<=map.size(); k++){
mapReceived.put(intReceived.getStringExtra("KEY"+k), intReceived.getParcelableExtra("VALUE"+k));
}
}
答案 1 :(得分:0)
For example, when sending the intent:
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("key", "value");
Intent intent = new Intent(this, MyOtherActivity.class);
intent.putExtra("map", hashMap);
startActivity(intent);
And then in the receiving Activity:
protected void onCreate(Bundle bundle) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
HashMap<String, String> hashMap = (HashMap<String, String>)intent.getSerializableExtra("map");
Log.v("HashMapTest", hashMap.get("key"));
}
答案 2 :(得分:0)
Hashmap
扩展了Serializable
,因此,如果您的POJO也扩展了Serializable
,您可以简单地通过意图将Hashmap<String,Object>
传递给另一个活动
Hashmap<String,Object> data = new Hashmap<String,Object>();
Intent intent = new Intent(Activity.this, Activity2.class);
intent.putSerializableExtra("data", data)