Skip to content Skip to sidebar Skip to footer

How To Pass An Arraylist Between Two Intent In Android

I am new in Android and I have a question regarding intent. I want to pass an String ArrayList between two activities by using intent. I have tried this: ` ArrayList

Solution 1:

you can easily to by using Gson

Intent intent = newIntent(this,Game.class);
intent.putExtra("Player",newGson().toJson(playerName));
startActivity(intent);

at Game.class

ArrayList<String> playerNameList = playerNameList = newArrayList<>();
String str =  getIntent().getStringExtra("Player");
playerNameList = newGson().fromJson(str,newTypeToken<ArrayList< String >>(){}.getType());

Solution 2:

Check your code to add data to ArrayList playerName. The code to putStringArrayListExtra to Intent and getStringArrayListExtra from Intent is correct.

Post a Comment for "How To Pass An Arraylist Between Two Intent In Android"