I have 2 screens corresponding to 2 activities on my Android app. I am trying to go back to the first activity from the second screen by clicking a Back button. Even though my first activity restarts, I get an annoying pop-up message "Unfortunately the app has stopped" as my app refreshes to go back to the first activity. I would like to not have this message appear.
I have tried different variations of code and the message appears each time :
@Override
public void onBackPressed() {
    startActivity(new Intent(this, MainActivity.class));
}
or
public void finishActivity(DisplayMessageActivity v){
  Intent intent = new Intent( this, MainActivity.class );
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);   
}
or even just
public void finishActivity(DisplayMessageActivity v){
    finish();
 }
 
    