diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/MainActivity.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/MainActivity.java index 0e45aff..0649149 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/MainActivity.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/MainActivity.java @@ -2,9 +2,11 @@ import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; import org.ntlab.radishforandroidstudio.R; +import org.ntlab.radishforandroidstudio.cactusClient.views.PlayerFragment; import org.ntlab.radishforandroidstudio.cactusClient.views.StartFragment; @@ -31,5 +33,24 @@ setContentView(R.layout.activity_main); } - + @Override + public void onBackPressed() { + FragmentManager manager = getSupportFragmentManager(); + if (manager == null) { + super.onBackPressed(); + return; + } + Fragment fragment = manager.findFragmentById(R.id.fragment_place); + if (fragment == null) { + super.onBackPressed(); + return; + } + if (fragment instanceof PlayerFragment) { + manager.beginTransaction().remove(fragment).commit(); + manager.popBackStack(); +// super.onBackPressed(); + return; + } + super.onBackPressed(); + } }