Home > Net >  How can you pass Dictionary to a new Activity in Android Studio?
How can you pass Dictionary to a new Activity in Android Studio?

Time:12-09

my both key and value needs to be string type

Dictionary AccountDetail= new Hashtable();
            AccountDetail.put("PersonName",personName);
            AccountDetail.put("Email",personEmail);

But in putString only single value variable is passing and this gives me error

startActivity(new Intent(getApplicationContext(),Maps.class)
.putExtra("AccountDetails" ,AccountDetail));
finish();

error says cant resolve method putExtra(java.lang.string.java.util.dictionary) i can use for loop and and send all elements but if here is method to pass all value at once let me know

CodePudding user response:

I suggest to you create a new class for your account detail information and then implement serializable or parcelable interface. Then you can pass complex data to another activity via Intent.

CodePudding user response:

Use a Bundle instead:

Bundle AccountDetail = new Bundle();
AccountDetail.put("PersonName", personName);
AccountDetail.put("Email", personEmail);
  • Related