Unregister preference change callback in onDestroy instead of onPause

Fix #496
This commit is contained in:
Mygod
2015-12-27 10:17:07 +08:00
parent 4d7bf8d707
commit b6fc013a06
2 changed files with 6 additions and 11 deletions
@@ -104,7 +104,6 @@ class Shadowsocks
var progressDialog: ProgressDialog = _
var progressTag = -1
var state = State.STOPPED
var prepared = false
var currentProfile = new Profile
var vpnEnabled = -1
var trafficCache: String = _
@@ -402,7 +401,6 @@ class Shadowsocks
protected override def onPause() {
super.onPause()
ShadowsocksApplication.profileManager.save
prepared = false
}
private def stateUpdate() {
@@ -517,7 +515,6 @@ class Shadowsocks
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) = resultCode match {
case Activity.RESULT_OK =>
prepared = true
serviceStart()
case _ =>
cancelStart()
@@ -166,18 +166,16 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
isProxyApps.setChecked(ShadowsocksApplication.settings.getBoolean(Key.isProxyApps, false)) // update
}
override def onPause {
super.onPause()
override def onDestroy {
super.onDestroy()
ShadowsocksApplication.settings.unregisterOnSharedPreferenceChangeListener(this)
}
def onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) = key match {
case Key.isNAT =>
activity.handler.post(() => {
activity.deattachService
activity.attachService
})
setEnabled(enabled)
case Key.isNAT => activity.handler.post(() => {
activity.deattachService
activity.attachService
})
case _ =>
}