How to Stop,Close or Finish an Activity on Android Java Programmatically

To close,stop or finish an activity, use this java code

// close this activity
 finish();




For example:

Intent i = new Intent(ThisActivity.this, NextActivity.class);
                startActivity(i);
                // close this activity
                finish();

This code here opens a new activity (NextActivity.class), then closes the Current Activity¬†(ThisActivity.this). the code “finish();” does this.

, , , , , ,

Post navigation

2 thoughts on “How to Stop,Close or Finish an Activity on Android Java Programmatically

  1. @Override
    public void onBackPressed() {
    startActivity(new Intent(this, MainActivity.class));
    finish();
    }
    next activity is start butt current activity not close

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.