Search code examples
androidandroid-fragmentsandroid-fragmentactivity

Send data from Activity1 to a fragment of Activity2 by using Inent


I want to send a string from a recyclerView of Activity1 to a fragment of Activity2 using intent. for better understanding, here is the demonstration image

enter image description here

so I'm fetching the key from recyclerView like this

    @Override
            protected void populateViewHolder(EventsViewHolder viewHolder, EventDetails model, int position) {

                viewHolder.setEventDate(model.getDate());
                viewHolder.setEventIcon(getApplicationContext(),model.getIcon());
                viewHolder.setEventTitle(model.getTitle());
                viewHolder.setEventDescription(model.getDescription());
                viewHolder.setEventTotalGuest(model.getTotal_guests());

                 String guest_key = getRef(position).getKey();

                viewHolder.mView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        Intent guestListIntent = new Intent(MainActivity.this, GuestListActivity.class);
                        startActivity(guestListIntent);
                        overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);

                    }
                });

            }

and now I want to send the guestKey by using intent from this activity to a fragment of GuestListActivity.class

I've tried Bundle but I can't send data. TIA


Solution

  • send the data as u send from activity to activity and receive in fragment as getActivity().getIntent() and then do as you receive data in activity.