-1

Hey I have an arraylist in activity1.class I want to get data from that array to show the data episodeList.size() in activity2.class here my list code

public class EpisodeAdapter  extends  RecyclerView.Adapter<EpisodeAdapter.EpisodeHolder>{
    private List<Episode> episodeList;
    public EpisodeAdapter(List<Episode> episodeList) {
        this.episodeList = episodeList;
    }
    @Override
    public EpisodeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_episode , null);
        EpisodeAdapter.EpisodeHolder mh = new EpisodeAdapter.EpisodeHolder(v);
        return mh;
    }

public int getItemCount() {
        return episodeList.size();
    }
Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
  • You can send that list with intent or you can store it in local database or strings.xml to access it from anywhere – Karan Mehta Feb 11 '20 at 06:24
  • send ArrayList with Parseable and then send it with bundle.putParceableArrayList(key, list). – Deepak Ror Feb 11 '20 at 06:26
  • Does this answer your question? [How to pass ArrayList from one activity to another?](https://stackoverflow.com/questions/21250339/how-to-pass-arraylistcustomeobject-from-one-activity-to-another) – Abhinav Suman Feb 11 '20 at 06:37

4 Answers4

0
Intent intent = new Intent(this, className);
            intent.putParcelableArrayListExtra("episodeList", episodeList);
            startActivity(intent);

and you can get it by

ArrayList<Episodes> list=getIntent.getparcelableArrayList("episodeList")

and don't forget to make the model class to parcelable

gowtham6672
  • 999
  • 1
  • 10
  • 22
0

You can use intents to pass values from one activity to another activity like this: In your current activity from where you want to pass ArrayList:

Intent intent = new Intent(CurrentActivity.this, TargetActivity.class);
intent.putStringArrayListExtra("key", your_array_list);
startActivity();

And in your Activity where you want to receive the values:

Intent intent = getIntent();  
ArrayList arrayList= intent.getStringArrayListExtra("key");
Dinesh Neupane
  • 382
  • 10
  • 19
0

I also had the same problem on my project. I just used SharedPreferences. It's like a local file in your project, but you cannot see it. You simply put the values inside and retrieve them in your 2nd Activity.

For more information: https://developer.android.com/training/data-storage/shared-preferences

0

Implement Parcelable in your ArrayList model.

Intent intent = new Intent(context, ServiceDetailActivity.class);
intent.putParcelableArrayListExtra("key", (ArrayList<? extends Parcelable>) arrayList);
startActivity(intent);

And get list in another activity

arrayList = getIntent().getParcelableArrayListExtra("key");
Rupesh Rathore
  • 319
  • 1
  • 9