Close activities Android studio

1

I have an app with a side menu. The doubt I have that every time I use one of the menu options opens a new window.

  } else if (id == R.id.cine) {
        Intent intent = new Intent(this.getApplication(), Cine.class);
        startActivityForResult(intent, 0);
        finish();

So far, well, but I doubt I have to put the finish to close the previous window.

But I do not like how it is since I would like to be able to go back to the previous one, giving it back without being closed. But if I remove the finish then I open windows and they are like many open applications.

Is there any way to do it?

Thanks!

    
asked by Montse Mkd 27.12.2018 в 15:58
source

1 answer

1

If the requirement is to use activities, in reality only open the Activity (it is not necessary to use startActivityForResul() ), to allow only one instance of the Activity defined for each Activity within your AndroidManifest.xml, the property:

android:launchMode="singleInstance"

the Main Activity does not end, with this when you return, your Main Activity will remain open.

 } else if (id == R.id.cine) {
        Intent intent = new Intent(this.getApplication(), Cine.class);
        startActivity(intent);   
        //startActivityForResult(intent, 0);
        //finish();
  }
    
answered by 27.12.2018 / 19:33
source