getExtras return null object

Viewed 33

I want to deliver one arraylist with activity when switching, but there is a problem. The object received by getExtras after switching the Activity is null. To add a little bit of explanation, when I clicked on the inner recircular view in a dual recycler view, I intended to move on to the new activity.

public class RoomAdapter extends RecyclerView.Adapter<RoomAdapter.CustomViewHolder> {
    private Context context;
    private ArrayList<RoomData> rooms;
    public ArrayList<StudnetInRoomData> students = new ArrayList<>();
    private LayoutInflater inflater;
    private RoomData room;
    View view;

    public RoomAdapter(Context context, ArrayList<RoomData> rooms) {
        this.context = context;
        this.rooms = rooms;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public CustomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = inflater.inflate(R.layout.single_room, parent, false);
        return new CustomViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull CustomViewHolder holder, int position) {
        room = rooms.get(position);
        holder.tvRoomNum.setText(String.valueOf(room.roomNum));
    }


    @Override
    public int getItemCount() {
        return rooms.size();
    }


    public class CustomViewHolder extends RecyclerView.ViewHolder {
        public TextView tvRoomNum;

        public CustomViewHolder(View itemView) {
            super(itemView);
            tvRoomNum = itemView.findViewById(R.id.tvRoomNumber);

            tvRoomNum.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(view.getContext(), PlusStudentActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("studentList", room.students);
                    intent.putExtras(bundle);
                    context.startActivity(intent);

                }
            });

        }
    }
}

In the new activity, call the getExtras function as shown below.

Intent intent = getIntent();
    Bundle bundle = intent.getExtras();
    ArrayList<StudnetInRoomData> students = (ArrayList< StudnetInRoomData>)bundle.getSerializable("studentList");
0 Answers
Related