Commit e4df3789 authored by Mygod's avatar Mygod

Fix back press crash

parent 25b6a307
......@@ -73,6 +73,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
var currentProfile = new Profile
var drawer: Drawer = _
private var currentFragment: ToolbarFragment = _
private lazy val profilesFragment = new ProfilesFragment()
private lazy val globalSettingsFragment = new GlobalSettingsFragment()
......@@ -341,9 +342,8 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
}
private def displayFragment(fragment: ToolbarFragment) {
val transaction = getFragmentManager.beginTransaction().replace(R.id.content, fragment)
if (fragment != profilesFragment) transaction.addToBackStack(null)
transaction.commitAllowingStateLoss()
currentFragment = fragment
getFragmentManager.beginTransaction().replace(R.id.content, fragment).commitAllowingStateLoss()
drawer.closeDrawer()
}
......@@ -426,6 +426,10 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
super.onStart()
registerCallback()
}
override def onBackPressed(): Unit =
if (currentFragment != profilesFragment) displayFragment(profilesFragment) else super.onBackPressed()
override def onStop() {
super.onStop()
unregisterCallback()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment