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 ...@@ -73,6 +73,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
var currentProfile = new Profile var currentProfile = new Profile
var drawer: Drawer = _ var drawer: Drawer = _
private var currentFragment: ToolbarFragment = _
private lazy val profilesFragment = new ProfilesFragment() private lazy val profilesFragment = new ProfilesFragment()
private lazy val globalSettingsFragment = new GlobalSettingsFragment() private lazy val globalSettingsFragment = new GlobalSettingsFragment()
...@@ -341,9 +342,8 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -341,9 +342,8 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
} }
private def displayFragment(fragment: ToolbarFragment) { private def displayFragment(fragment: ToolbarFragment) {
val transaction = getFragmentManager.beginTransaction().replace(R.id.content, fragment) currentFragment = fragment
if (fragment != profilesFragment) transaction.addToBackStack(null) getFragmentManager.beginTransaction().replace(R.id.content, fragment).commitAllowingStateLoss()
transaction.commitAllowingStateLoss()
drawer.closeDrawer() drawer.closeDrawer()
} }
...@@ -426,6 +426,10 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -426,6 +426,10 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
super.onStart() super.onStart()
registerCallback() registerCallback()
} }
override def onBackPressed(): Unit =
if (currentFragment != profilesFragment) displayFragment(profilesFragment) else super.onBackPressed()
override def onStop() { override def onStop() {
super.onStop() super.onStop()
unregisterCallback() 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