0

I have an Adapter which uses some custom object list. I wanted to pass the clicked object's to the other activity. So I made the object class implement Parcelable.

To send the data from the adapter

view.findViewById(R.id.play_btn).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(getContext(), YouTubePlayerActivity.class);
        Bundle bundle = new Bundle();
        bundle.putParcelable("data", movie));
        intent.putExtras(bundle);
        mContext.startActivity(intent);

To receive the data in the destination activity

    Bundle b = getIntent().getExtras();
    ArrayList<Video> videos = b.getParcelable("data");

But when I run it, it would pass nothing. I tried passing other simpler values like strings and integer and they were too not passed.

Then I had to achieve the task by creating interface. And it worked. But I still don't understand this unexpected behavior when starting activity from adapters. Can you please answer the reason behind this unexpected behavior?

  • what does `movie` represents? is it a single object or a list? – Atef Hares Mar 24 '19 at 15:08
  • seems a duplicate of https://stackoverflow.com/questions/1441871/passing-data-of-a-non-primitive-type-between-activities-in-android – jcuypers Mar 24 '19 at 15:09
  • @AtefHares it is a list. I know i made a typo while typing the code here. But It didn't matter what I pass –  Mar 24 '19 at 18:51

0 Answers0