androidandroid-lifecycleactivity-finish

How to use the finish() method in Android


As a newcomer to Android development, I would like to learn how to terminate an activity in Android. I have completed one project already and the previous activity functioned properly. Could you please explain how to finish that activity quickly when the next activity begins?


Solution

  • After I start the activity, I call the finish() method:

    Intent i=new Intent(mainclass.this,nextclass.class);
    startActivity(i);
    finish();
    

    Then the previous activity(mainclass) is finished.