AndroidBegginer AndroidBegginer - 9 months ago 70
Android Question

Start Activity from RecyclerView.Adapter with bundled Object

I'm using RecyclerView to populate CardViews with my object "Income". Now I need one of the buttons in CardView to start new Activity and send that object to it.

Here's part of my button's onClickListener in Adapter:

holder.editButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {

public void editAt(Income income){
Intent i = new Intent(context,IncomeAddActivity.class);
Bundle bundle = new Bundle();

// here I want to send that "income" object



Is there any easy method to do this, or my approach is totally wrong?

Answer Source

You need to make your class Income implements the interface Serializable. Then you can do this:

Bundle bundle = new Bundle();
bundle.putSerializable("object", income);