DrNutsu
DrNutsu

Reputation: 476

How to get Hashmap of Arraylist Extra from previous intent?

I put hashmap of arraylist extra in old intent (SaleActivity)

Intent newActivity = new Intent(SaleActivity.this,UpdateActivity.class);
newActivity.putExtra("saleArrList", saleArrList);
startActivity(newActivity);

Then, I get it from newactivity (UpdateActivity)

Intent intent= getIntent();
final ArrayList<HashMap<String, String>> saleArrList = intent.get...Extra("saleArrList");

What code in ... ,that i should use. Thanks for all answer a lots.

Upvotes: 0

Views: 2015

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234847

When you put the extra, it treated your array list as a Serializable. You should use:

Serializable serialized = intent.getSerializableExtra("saleArrList");

Unfortunately, casting this to ArrayList<HashMap<String,String>> will generate a compiler warning about unchecked conversions. This is due to how type erasure works in Java. There's no clean and easy way to get rid of this warning. The unclean way is to suppress the warning by putting

@SuppressWarnings("unchecked")

at the top of your method. This suppresses all unchecked conversion warnings, so it is not particularly safe. However, you can then write:

final ArrayList<HashMap<String, String>> saleArrList =
    (ArrayList<HashMap<String,String>>)intent.getSerializableExtra("saleArrList");

Upvotes: 1

Related Questions