[Solved] How to start activity with two buttons


Try this

public class MainActivity extends AppCompatActivity {

Boolean launch = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button btn1 = (Button) findViewById(R.id.button);
    Button btn2 = (Button) findViewById(R.id.button2);

    btn1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            launch = true;
        }
    });

    btn2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (launch == true)
            {
                Intent i = new Intent(MainActivity.this,Main2Activity.class);
                startActivity(i);
            }
            else
            {
                //do your stuff
            }
        }
    });
}
}

solved How to start activity with two buttons