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?