help with sending data to two activitys

0

My problem is that I do not know how to direct the data to two activitys of the selected item ... I am a newbie and I was testing with the if and it seems to be wrong because I can not select the other items.

viewHolder.setOnClickListener(new ViewHolder.ClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    String mTitle = getItem(position).getTitle();
                    String mDesc = getItem(position).getDescripcion();
                    String mImage = getItem(position).getImage();
                    String mLugar = getItem(position).getLugar();

                    if(position ==0){
                    Intent intent=new Intent(view.getContext(),PostDetailActivity.class);
                    intent.putExtra("image", mImage);
                    intent.putExtra("title", mTitle);
                    intent.putExtra("descripcion", mDesc);
                    intent.putExtra("lugar",mLugar);
                    startActivity(intent);
                    }
                    if(position ==0){
                    Intent intent=new 
                    Intent(view.getContext(),PostDetail2Activity.class);
                    intent.putExtra("image", mImage);
                    intent.putExtra("title", mTitle);
                    intent.putExtra("descripcion", mDesc);
                    intent.putExtra("lugar",mLugar);
                    startActivity(intent);
                    }
                }
                @Override
                public void onItemLongClick(View view, int position) {
                }
            });
            return viewHolder;

in this activity I put a button to enter the other activity but I get empty:

    String image =getIntent().getStringExtra("image");
    String title=getIntent().getStringExtra("title");
    String desc=getIntent().getStringExtra("descripcion");
    String lug=getIntent().getStringExtra("lugar");

    mTitleTv.setText(title);
    mDetailTv.setText(desc);
    Picasso.get().load(image).into(mImageIv);

    mBtn_hora.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent =new Intent(PostDetailActivity.this,PostDetail2Activity.class);
            startActivity(intent);
        }
    });
    
asked by renzofu 29.11.2018 в 16:54
source

2 answers

0

after each

startActivity(intent);

add finish()

startActivity(intent);
finish()

and catch the intens you send in your second activity

    
answered by 29.11.2018 в 17:37
0

I suggest you first review this question:

Send data between activities

If you are sending the data to PostDetail2Activity

 Intent intent=new Intent(view.getContext(),PostDetail2Activity.class);
 intent.putExtra("image", mImage);
 intent.putExtra("title", mTitle);
 intent.putExtra("descripcion", mDesc);
 intent.putExtra("lugar",mLugar);
 startActivity(intent);

to receive the data correctly, you must receive it within the onCreate() of your Activity , in this case PostDetail2Activity that you defined in Intent :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

     String image =getIntent().getStringExtra("image");
     String title=getIntent().getStringExtra("title");
     String desc=getIntent().getStringExtra("descripcion");
     String lug=getIntent().getStringExtra("lugar");

    ...
    ...

}

    
answered by 29.11.2018 в 18:39