Skip to content

Commit

Permalink
Fix fragment transaction after onStop
Browse files Browse the repository at this point in the history
  • Loading branch information
nkming2 committed Sep 12, 2016
1 parent 0ae2fab commit 19ebf95
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/main/kotlin/com/nkming/powermenu/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MainActivity : AppCompatActivity()
{
PersistentService.hideView(this)
}
_isStop = false
}

override fun onStop()
Expand All @@ -59,6 +60,7 @@ class MainActivity : AppCompatActivity()
PersistentViewHelper.startIfNecessary(this)
SystemOverrideService.startIfNecessary(this)
}
_isStop = true
}

override fun onUserLeaveHint()
Expand Down Expand Up @@ -90,14 +92,22 @@ class MainActivity : AppCompatActivity()
}
else
{
// Disable the standard activity launch animation
overridePendingTransition(0, 0)
setContentView(R.layout.activity_main)
if (savedInstanceState == null)
if (_isStop)
{
supportFragmentManager.beginTransaction()
.add(R.id.container, MainFragment())
.commit()
// User has closed/hid the app
super.finish()
}
else
{
// Disable the standard activity launch animation
overridePendingTransition(0, 0)
setContentView(R.layout.activity_main)
if (savedInstanceState == null)
{
supportFragmentManager.beginTransaction()
.add(R.id.container, MainFragment())
.commit()
}
}
}
}
Expand All @@ -113,4 +123,5 @@ class MainActivity : AppCompatActivity()
}

private var _isAnimateClose = true
private var _isStop = false
}

0 comments on commit 19ebf95

Please sign in to comment.