How to pass Collections like ArrayList, etc from one Activity to another as we used to pass Strings, int with help of putExtra method of Intent?
Can anyone please help me as i want to pass a List<String> from one Activity to another?
You can pass an ArrayList<E> the same way, if the E type is Serializable.
You would call the putExtra (String name, Serializable value) of Intent to store, and getSerializableExtra (String name) for retrieval.
Example:
ArrayList<String> myList = new ArrayList<String>();
intent.putExtra("mylist", myList);
In the other Activity:
ArrayList<String> myList = (ArrayList<String>) getIntent().getSerializableExtra("mylist");
Please note that serialization can cause performance issues: it takes time, and a lot of objects will be allocated (and thus, have to be garbage collected).
First you need to create a Parcelable object class, see the example
public class Student implements Parcelable {
int id;
String name;
public Student(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
#Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
#Override
public void writeToParcel(Parcel dest, int arg1) {
// TODO Auto-generated method stub
dest.writeInt(id);
dest.writeString(name);
}
public Student(Parcel in) {
id = in.readInt();
name = in.readString();
}
public static final Parcelable.Creator<Student> CREATOR = new Parcelable.Creator<Student>() {
public Student createFromParcel(Parcel in) {
return new Student(in);
}
public Student[] newArray(int size) {
return new Student[size];
}
};
}
And the list
ArrayList<Student> arraylist = new ArrayList<Student>();
Code from Calling activity
Intent intent = new Intent(this, SecondActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("mylist", arraylist);
intent.putExtras(bundle);
this.startActivity(intent);
Code on called activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Bundle bundle = getIntent().getExtras();
ArrayList<Student> arraylist = bundle.getParcelableArrayList("mylist");
}
use putExtra to pass value to an intent. use getSerializableExtra method to retrieve the data
like this
Activity A :
ArrayList<String> list = new ArrayList<String>();
intent.putExtra("arraylist", list);
startActivity(intent);
Activity B:
ArrayList<String> list = getIntent().getSerializableExtra("arraylist");
I tried all the proposed techniques but none of them worked and stopped my app from working and then I finally succedded. Here is how I did it...
In main activity I did this:
List<String> myList...;
Intent intent = new Intent...;
Bundle b=new Bundle();
b.putStringArrayList("KEY",(ArrayList<String>)myList);
intent_deviceList.putExtras(b);
....startActivity(intent);
To get the data in the new Activity:
List<String> myList...
Bundle b = getIntent().getExtras();
if (b != null) {
myList = bundle.getStringArrayList("KEY");
}
I hope this will help someone...
To pass ArrayList from one activity to another activity, one should include
intent.putStringArrayListExtra(KEY, list); //where list is ArrayList which you want to pass
before starting the activity.And to get the ArrayList in another activity include
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
temp = bundle.getStringArrayList(KEY); // declare temp as ArrayList
}
you will be able to pass ArrayList through this.Hope this will be helpful to you.
Use of ViewModel is better fix than Serializable or Parcelable
Related
could someone please answer my question. in my activity class.java, I have an intent and i want to send an object using intent. when I searched for it, the results were I have to implement parcelable to the class "object" that I want to send it. I did that but the thing is I want to put two objects to be sent to main2activity.java, when I tried to do that, my app crashed, when I debugged it said that main2activity has much intent? so my question is how can I send two objects using put extra, and get them in the other java using getintent.getparcelableextra()?
mainactivity.java
clickedplace is an object of class called Place
Intent myintent = new Intent(getApplicationContext(), localpopup.class);
myintent.putExtra("localprice",clickedplace.getTicketId().getLocalPrice());
myintent.putExtra("placeobject", clickedplace.getId());
main2activity.java
localpriceplace of type double
getpressplace of type Place
localpriceplace= getIntent().getParcelableExtra("localprice");
getpressedplace= (Place) getIntent().getParcelableExtra("placeobject");
You should be able to do this by creating a Bundle and putting each Intent into it with a String key. In "main2activity" you should retrieve them by name.
But the bundle into a new Intent and send that to main2activity
Otherwise, if you are putting data into each Intent and then sending the Intent directly to main2activity, you will need to implement "onNewIntent" in main2activity to get the new data.
Hi Please follow below link which is useful to you and solved your problem.
http://www.vogella.com/tutorials/AndroidParcelable/article.html
Hope above link helps you.
If you want to auto generate those parcelable model class then follow below link which saves your time.
https://github.com/mcharmas/android-parcelable-intellij-plugin
Please check below code:
1) You need to create your model class as a parcelable follow by above link.
2) To pass data to other activity:
intent.putExtra("student", new Student("1","Mike","6") // which is your model class object passing);
3)GetData into Other Activity Using intent:
Bundle data = getIntent().getExtras();
Student student = (Student) data.getParcelable("student");
// after you get all data from student.
Hope you understand.
Try this implements Parcelable to your Place Model
Intent myintent = new Intent(getApplicationContext(), localpopup.class);
myintent.putExtra("placeModel",clickedplac);
Receive
placeModel= getIntent().getParcelableExtra("placeModel");
String price=placeModel.getTicketId().getLocalPrice();
String Id=placeModel.getId()
ActivityB.java
public class ActivityB {
private static final String ARG_DATA1 = "Data1";
private static final String ARG_DATA2 = "Data2";
public static startActivityB (Context context, Data1 data1, Data2 data2) {
Bundle bundle = new Bundle();
bundle.putParcelable(ARG_DATA1, data1);
bundle.putParcelable(ARG_DATA2, data2);
Intent intent = new Intent(context, ActivityB.class);
intent.putExtras(bundle);
context.startActivity(intent);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
Data1 data1 = bundle.getParcelable(ARG_DATA1);
Data2 data2 = bundle.getParcelable(ARG_DATA2);
}
}
Data1.java
public static class Data1 implements Parcelable {
public static final Creator<Data1> CREATOR = new Creator<Data1>() {
#Override
public Data1 createFromParcel(Parcel in) {
return new Data1(in);
}
#Override
public Data1[] newArray(int size) {
return new Data1[size];
}
};
protected Data1(Parcel in) {
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
}
}
and Data2.java should also implement Parcelable.
And lastly, to start ActivityB from ActivityA,
Data1 data1;
Data2 data2;
ActivityB.startActivityB(ActivityA.this, data1, data2);
I need to pass a large list of data from one activity to another activity,which way is better?
First way(for example):
ArrayList<myModel> myList = new ArrayList<myModel>();
intent.putExtra("mylist", myList);
Second way(for example) :
ActivityTwo act = new ActivityTwo();
act.getDataMethod(listValues);
Intent i = new Intent(this, ActivityTwo.class);
startActivity(i);
And in another activity(ActivityTwo) I get data from getDataMethod.
If the data you want to send is really big (around 1MB). The best way to pass it is to store it in persistent storage in ActivityA and access it in ActivityB.
The approach with passing it via Parcerable/Serializable is risky as you may end up with TransactionTooLargeException when trying to pass around 1MB of data.
The approach with passing it via Singleton class is even worse as when you are in ActivityB and application is recreated (it was long in background/memory was low) you will loose data from singleton (process is recreated) and nobody will set it, ActivityB will be launched and it wont have data from AcitvityA (as it was never created).
In general you shouldn't pass data through intents, you should pass arguments/identifiers which then you can use to fetch data from db/network/etc.
Best way to pass large data list from one Activity to another in Android is Parcelable . You first create Parcelable pojo class and then create Array-List and pass into bundle like key and value pair and then pass bundle into intent extras.
Below I put one sample User Pojo class that implements Parcelable interface.
import android.os.Parcel;
import android.os.Parcelable;
/**
* Created by CHETAN JOSHI on 2/1/2017.
*/
public class User implements Parcelable {
private String city;
private String name;
private int age;
public User(String city, String name, int age) {
super();
this.city = city;
this.name = name;
this.age = age;
}
public User(){
super();
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
#SuppressWarnings("unused")
public User(Parcel in) {
this();
readFromParcel(in);
}
private void readFromParcel(Parcel in) {
this.city = in.readString();
this.name = in.readString();
this.age = in.readInt();
}
public int describeContents() {
return 0;
}
public final Parcelable.Creator<User> CREATOR = new Parcelable.Creator<User>() {
public User createFromParcel(Parcel in) {
return new User(in);
}
public User[] newArray(int size) {
return new User[size];
}
};
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(city);
dest.writeString(name);
dest.writeInt(age);
}
}
ArrayList<User> info = new ArrayList<User>();
info .add(new User("kolkata","Jhon",25));
info .add(new User("newyork","smith",26));
info .add(new User("london","kavin",25));
info .add(new User("toranto","meriyan",30));
Intent intent = new Intent(MyActivity.this,NextActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("user_list",info );
intent.putExtras(bundle);`
startActivity(intent );
To me serialized objects/list is better way.
`Intent intent = ....
Bundle bundle = new Bundle();
ArrayList<String> myList = new ArrayList<String>();
bundle.putSerializable("mylist", myList);
intent.putExtras(bundle);`
Use the first approach. However you will need to use the following method call to put it into the Intent:
ArrayList<String> myList = new ArrayList<String>();
intent.putStringArrayListExtra("mylist",myList);
The to get the list out of the intent in the receiving Activity:
ArrayList<String> myList = getIntent().getStringArrayListExtra("mylist");
If you have a huge list of data it is better way to save the data in Singleton java class and use set/get to save & get the data in application level.
Sharing large data as intent bundle may chances to lose data.
Application.class
add this in you manifest file
<application
android:name=".App"
-----
</application>
public class App extends Application {
public ArrayList<Object> newsList;
#Override
public void onCreate() {
super.onCreate();
}
public void setHugeData(ArrayList<Object> list){
this.newsList = list;
}
public ArrayList<Object> getHugeData(){
return newsList;
}
}
in ActivityA.class
ArrayList<Object> info = new ArrayList<>();
// save data
((App)getApplication()).setHugeData(info);
in ActvityB.class
ArrayList<Object> info = new ArrayList<>();
// get the data
info = ((App)getApplication()).getHugeData();
You can use such libraries as Eventbus to pass models through activities or you can put your model in ContentValues (https://developer.android.com/reference/android/content/ContentValues.html) class - it is parcable and you can pass it through intent. A good practice is to implement two methods in your Model class - toContentValues() and fromContentValues().
Something like this:
public class DealShort extends BaseResponse implements ContentValuesProvider {
#SerializedName("id")
#Expose
private long id = -1;
#SerializedName("full_price")
#Expose
private double fullPrice;
public static DealShort fromContentValues(ContentValues cv) {
DealShort deal = new DealShort();
deal.id = cv.getAsLong(DbContract.Product.SERVER_ID);
deal.fullPrice = cv.getAsLong(DbContract.CategoriesProducts.CATEGORY_ID);
}
public ContentValues toContentValues() {
ContentValues cv = new ContentValues();
cv.put(DbContract.Product.SERVER_ID, id);
cv.put(DbContract.Product.FULL_PRICE, fullPrice);
return cv;
}
}
1,You can use Singleton class,like below code:
public class MusicListHolder {
private ArrayList<MusicInfo> musicInfoList;
public ArrayList<MusicInfo> getMusicInfoList() {
return musicInfoList;
}
public void setMusicInfoList(ArrayList<MusicInfo> musicInfoList) {
this.musicInfoList = musicInfoList;
}
private static final MusicListHolder holder = new MusicListHolder();
public static MusicListHolder getInstance() {
return holder;
}
}
it's easy and useful!
2,You can use Application,just put your data in Application before you use it!
3,You can use Eventbus
4,You can put your data in a file/sqlite/...,maybe it's slow and conflict,but it's workable
I have a class called Service, which is used to create Service objects using this constructor
public Service(int id, String service_name, String service_code) {
this.id = id;
this.service_name = service_name;
this.service_code = service_code;
}
then I create a list call service list as with the following signature
List<Service> serviceList = new ArrayList<Service>
I have try to pass this ArrayList through Intent Object like this
Intent i = new Intent(Classname.this, anotherClass.class);
i.putExtras("serviceList",serviceList);
startActivity(i);
But it fails. What is the way I pass through intent with ArrayList object.
Your custom class has to implement Parcelable or Serializable in order to serialize/de-serialize within an Intent.
Your class Service has to look like this for example (used a generator http://www.parcelabler.com/)
public class Service implements Parcelable {
private int id;
private String service_name;
private String service_code;
public Service(int id, String service_name, String service_code) {
this.id = id;
this.service_name = service_name;
this.service_code = service_code;
}
protected Service(Parcel in) {
id = in.readInt();
service_name = in.readString();
service_code = in.readString();
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(service_name);
dest.writeString(service_code);
}
#SuppressWarnings("unused")
public static final Parcelable.Creator<Service> CREATOR = new Parcelable.Creator<Service>() {
#Override
public Service createFromParcel(Parcel in) {
return new Service(in);
}
#Override
public Service[] newArray(int size) {
return new Service[size];
}
};
}
Then you can use getIntent().getParcelableArrayListExtra() with casting
ArrayList<Service> serviceList= intent.<Service>getParcelableArrayList("list"));
For sending you use it like this
intent.putParcelableArrayListExtra("list", yourServiceArrayList);
Note that the yourServiceArrayList should be an ArrayList
if it is List the you can pass through
intent.putParcelableArrayListExtra("list", (ArrayList<? extends Parcelable>) yourServiceArrayList);
You can use parcelable interface for 'Service' class, and send object through
intent using 'putParcelableArrayListExtra' method and to retrive data you can use
'getParcelableArrayListExtra'.
For your reference
refer this link
Implement object class with Serializable .
eg.
class abc implements Serializable{
//your code
}
then try this code
ArrayList<abc> fileList = new ArrayList<abc>();
Intent intent = new Intent(MainActivity.this, secondActivity.class);
intent.putSerializable("arraylisty",filelist);
startActivity(intent);
and on other side receive intent like
your arraylist objact=intent.getSerializableExtra(String name)
I have a class that I'm using for parsing data from a csv file (called CSVReader), inside of that there is some methods for the parsing as well as a couple of strings and a list that is of a custom object type (List allRecords).
What I'm doing is when the app loads, parsing all the data into that list and then trying to pass that information along to the next activity but inside the next activity I keep getting allRecords as being null.
LoginActivity
CSVReader data = new CSVReader();
data.populateRecords(this);
Intent intent = new Intent(LoginActivity.this, Find.class);
Bundle bundle = new Bundle();
bundle.putParcelable("list", data);
intent.putExtra("bundle", bundle);
startActivity(intent);
I've gone through the debugger and the bundle definitely has the data in there.
Find
Intent intent = getIntent();
Bundle bundle = intent.getBundleExtra("bundle");
data = (CSVReader) bundle.getParcelable("list");
Using the debugger still, and mMap (in the bundle) is now null and so is data.
Am I doing something wrong? Both classes DummyData and CSVReader implement Parcelable.
EDIT: Adding custom class CSVReader:
List<DummyData> allRecords;
private String base;
private String location;
private String partner;
public static Creator<CSVReader> CREATOR = new Creator<CSVReader>(){
#Override
public CSVReader createFromParcel(Parcel source){
return new CSVReader(source);
}
#Override
public CSVReader[] newArray(int size) {
return new CSVReader[size];
}
};
private CSVReader(Parcel in){
allRecords = new ArrayList<DummyData>();
in.readTypedList(allRecords, DummyData.CREATOR);
base = in.readString();
location = in.readString();
partner = in.readString();
}
...
...
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(base);
dest.writeString(location);
dest.writeString(partner);
dest.writeList(allRecords);
}
[EDIT]
I was looking over your code again, and noticed you're writing the List to the parcel LAST and reading the list from the parcel FIRST. You have to read items from the parcel in the order they are written. Try putting dest.writeList(allRecords) at the top of the method so it is the first item written, or you can put in.readList(allRecords, DummyData.class.getClassLoader()) at the bottom of the list in that method.
Give it a shot.
//////////////////////////////////////////////
From the docs,
public final void readTypedList (List<T> list, Creator<T> c)
Read into the given List items containing a particular object type
that were written with writeTypedList(List) at the current
dataPosition(). The list must have previously been written via
writeTypedList(List) with the same object type.
You're using writeList() to write the data to the parcel. Try using writeTypedList(). You could also try changing readTypedList() with readList() I believe. Something like:
in.readList(allRecords, CSVReader.class.getClassLoader());
Hope this helps.
If you plan to pass data to another activity, you need to use objects of classes that implement Parcelable. Here is an example,
package com.weather.model;
import java.util.ArrayList;
import java.util.List;
import android.os.Parcel;
import android.os.Parcelable;
public class Forcast implements Parcelable {
private String id;
private String code;
private String message;
private City city;
private String count;
private List<Weather> weatherList = new ArrayList<Weather>();
public Forcast(){
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public City getCity() {
return city;
}
public void setCity(City city) {
this.city = city;
}
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
public List<Weather> getWeatherList() {
return weatherList;
}
public void setWeatherList(List<Weather> weather) {
this.weatherList = weather;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(id);
dest.writeString(code);
dest.writeString(message);
dest.writeParcelable(city, flags);
dest.writeString(count);
dest.writeList(weatherList);
}
public static final Parcelable.Creator<Forcast> CREATOR = new Parcelable.Creator<Forcast>() {
#Override
public Forcast createFromParcel(Parcel source) {
return new Forcast(source);
}
#Override
public Forcast[] newArray(int size) {
return new Forcast[size];
}
};
protected Forcast(Parcel in){
id = in.readString();
code = in.readString();
message = in.readString();
city = (City)in.readParcelable(City.class.getClassLoader());
count = in.readString();
in.readList(weatherList, Weather.class.getClassLoader());
}
}
I included City model so you can see how it goes for an object in comparison to list of objects. Assume you have a Forcast instance with all the values as 'forcast' ( Forcast forcast = new Forcast() or something similar)
Intent intent = new Intent(this, SomeActivity.class);
intent.putExtra(com.weather.model,forcast)
startActivity(intent)
I hope that helps
You need to put bundle object by using putExtras method. Then you can get the bundle by using getIntent().getExtras().
Intent intent = new Intent(LoginActivity.this, Find.class);
Bundle bundle = new Bundle();
bundle.putParcelable("list", data);
intent.putExtras( bundle);
startActivity(intent);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
data = (CSVReader) bundle.getParcelable("list");
I have searched a few topics but not found a solution to my problem.
public class Series implements Parcelable {
private String name;
private int numOfSeason;
private int numOfEpisode;
/** Constructors and Getters/Setters have been removed to make reading easier **/
public Series(Parcel in) {
String[] data = new String[3];
in.readStringArray(data);
this.name = data[0];
this.numOfSeason = Integer.parseInt(data[1]);
this.numOfEpisode = Integer.parseInt(data[2]);
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeStringArray(new String[] { this.name,
String.valueOf(this.numOfSeason),
String.valueOf(this.numOfEpisode) });
}
private void readFromParcel(Parcel in) {
name = in.readString();
numOfSeason = in.readInt();
numOfEpisode = in.readInt();
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
#Override
public Series createFromParcel(Parcel in) {
return new Series(in);
}
#Override
public Series[] newArray(int size) {
return new Series[size];
}
};
}
In my MainActivity I have an ArrayList. To make the list dynamically editeable I need to pass it to another activity where I can edit it.
ArrayList<Series> listOfSeries = new ArrayList<Series>();
public void openAddActivity() {
Intent intent = new Intent(this, AddActivity.class);
intent.putParcelableArrayListExtra(
"com.example.episodetracker.listofseries",
(ArrayList<? extends Parcelable>) listOfSeries);
startActivity(intent);
}
I need to cast the list, otherwise Eclipse gives me the following Error message.
The method putParcelableArrayListExtra(String, ArrayList) in the type Intent is not applicable for the arguments (String, List)
Is this the correct way to do it?
ArrayList<Series> list = savedInstanceState
.getParcelableArrayList("com.example.episodetracker.listofseries");
This is the way I try to read the data in another activity.
It's crashing on the line above. namely the getParcelableArrayList part.
The problem is in writing out to the parcel and reading in from the parcel ...
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(numOfSeason);
dest.writeInt(numOfEpisode);
}
private void readFromParcel(Parcel in) {
name = in.readString();
numOfSeason = in.readInt();
numOfEpisode = in.readInt();
}
What you write out has to match what you read in...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i = new Intent(this,SecondActivity.class);
ArrayList<testparcel> testing = new ArrayList<testparcel>();
i.putParcelableArrayListExtra("extraextra", testing);
startActivity(i);
}
/**********************************************/
public class SecondActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<testparcel> testing = this.getIntent().getParcelableArrayListExtra("extraextra");
}
}
The above code is having onCreate() from two different activities. The first one launches the second one; and it works fine I was able to pull the parcelable without issue.
You should use the putParcelableArrayListExtra() method on the Intent class.
I've used putParcelableArrayList(<? extends Parcelable>) from a Bundle Object. Not directly from an Intent Object.(I don't really know what's the difference). but i use to use in this way:
ArrayList<ParcelableRow> resultSet = new ArrayList<ParcelableRow>();
resultSet = loadData();
Bundle data = new Bundle();
data.putParcelableArrayList("search.resultSet", resultSet);
yourIntent.putExtra("result.content", data);
startActivity(yourIntent);
Later on your new activity you can populate the data recently inserted on the Bundle object like this:
Bundle data = this.getIntent().getBundleExtra("result.content");
ArrayList<ParcelableRow> result = data.getParcelableArrayList("search.resultset");
Just remember that your ArrayList<> must contain only parcelable objects. and just to make sure that your have passed the data you may check if the data received is null or not, just to avoid issues.
Maybe this helps someone.. else my problem was that I used write and readValue but it should match type like writeInt, readInt writeString, readString and so forth
I am doing it in this way:
var intent = Intent(this#McqActivity,ResultActivity::class.java)
intent.putParcelableArrayListExtra("keyResults", ArrayList(resultList))
// resultList is of type mutableListOf<ResultBO>()
startActivity(intent)
And for making the class Parcelable . I simply do two operation first I used #Parcelize Annotation above my data class and secondly I inherit it with Parcelable like below..
import kotlinx.android.parcel.Parcelize
import android.os.Parcelable
#Parcelize // Include Annotion
data class ResultBO(val questionBO: QuestionBO) : Parcelable {
constructor() : this(QuestionBO())
}
And at receiving end
if (intent != null) {
var results = intent.getParcelableArrayListExtra<Parcelable>("keyResults")
}
You can pass Parcelable ArrayList
Sender Activity ->
startActivity(Intent(this, SenderActivity::class.java).apply { putExtra("getList",list)})
Receiver Activity ->
private lateinit var list: ArrayList<List>
list = this.intent.extras?.getParcelableArrayList("getList")!!
And you will get all Arraylist in list.