leithdm
4/28/2020 - 7:10 PM

Intent: moving between activities 101

    //assuming we are clicking a button to go to next activity
    
    //short version
    startActivity(new Intent(MainActivity.this, SecondActivity.class); 
    
    //verbose version
    public void goToNext(View view) {
        Intent intent = new Intent(getApplicationContext(), SecondActivity.class); //SecondActivity.class is the activity to move to
        startActivity(intent);
    }
    
    //going from second activity back to first
    public void goBack(View view) {
      finish(); 
    }
    
    //we use finish() instead of duplicating code from first paragraph because Android has its own back button, and you end up just piling Intents upon Intents if user goes between them