On my start(home) screen I have 3 buttons. Button_1, Button_2 and Button_3. They are all open same Activity B. So here I need depending on which button is clicked on home screen to open different Activity C after second activity. I can make it with 2 buttons but when I try with third button with elseif it doesn't work properly. Here is how I trying it. Home screen
Button_1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, SecondActivity.class); intent.putExtra("isButtonClicked",true); startActivity(intent); } }); Button_2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, SecondActivity.class); intent.putExtra("button", true); startActivity(intent); } }); Button_3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, SecondActivity.class); intent.putExtra("isButtonClicked",false); startActivity(intent); } }); Here is SecondActivity
boolean isButton = getIntent().getBooleanExtra("isButtonClicked",false); boolean button = getIntent().getBooleanExtra("button",true); if(isButton) { Intent newActivity = new Intent(SecondActivity.this, ThirdActivity.class); newActivity.putExtra("Position", Position); newActivity.putExtra("resultServer", resultServer); newActivity.putExtra("text", MyArrList.get(position).get("text").toString()); newActivity.putExtra("name", MyArrList.get(position).get("name").toString()); startActivity(newActivity); } else if (button) { Intent newActivity = new Intent(SecondActivity.this, FourthActivity.class); newActivity.putExtra("Position", Position); newActivity.putExtra("resultServer", resultServer); newActivity.putExtra("id", MyArrList.get(position).get("id").toString()); startActivity(newActivity); } else { Intent newActivity = new Intent(SecondActivity.this, FifthActivity.class); newActivity.putExtra("Position", Position); newActivity.putExtra("resultServer", resultServer); newActivity.putExtra("id", MyArrList.get(position).get("id").toString()); startActivity(newActivity); } As you can see after second activity which is same for all 3 buttons then I want to load different. If I put it just with if{}else{} i.e. for two buttons is working good. But now I get same result on Button_2 and Button_3.
same result on button 2 and 3... which block ?elseif{}else{}... it is openFifthActivity.classfor both buttons.