diff --git a/src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala b/src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala index e6cbbeaf..c304f559 100644 --- a/src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala +++ b/src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala @@ -67,11 +67,13 @@ trait ServiceBoundContext extends Context { } catch { case ignored: RemoteException => // Nothing } + callback = null } if (connection != null) { unbindService(connection) connection = null } + bgService = null } } } diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index 9b652522..895c487f 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -157,6 +157,13 @@ class Shadowsocks // Services var currentServiceName = classOf[ShadowsocksNatService].getName + private val callback = new IShadowsocksServiceCallback.Stub { + def stateChanged(state: Int, msg: String) = onStateChanged(state, msg) + def trafficUpdated(txRate: String, rxRate: String, txTotal: String, rxTotal: String) = + Shadowsocks.this.trafficUpdated(txRate, rxRate, txTotal, rxTotal) + } + + def attachService: Unit = attachService(callback) override def onServiceConnected() { // Update the UI @@ -377,16 +384,7 @@ class Shadowsocks }) // Bind to the service - handler.post(() => { - attachService(new IShadowsocksServiceCallback.Stub { - override def stateChanged(state: Int, msg: String) { - onStateChanged(state, msg) - } - override def trafficUpdated(txRate: String, rxRate: String, txTotal: String, rxTotal: String) { - Shadowsocks.this.trafficUpdated(txRate, rxRate, txTotal, rxTotal) - } - }) - }) + handler.post(() => attachService) } def reloadProfile() { diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala index 684fc0ed..b63c7d81 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala @@ -67,7 +67,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan }) } - override def onResume = { + override def onResume { super.onResume isProxyApps.setChecked(ShadowsocksApplication.settings.getBoolean(Key.isProxyApps, false)) // update } @@ -75,9 +75,8 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan def onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) = key match { case Key.isNAT => if (ShadowsocksApplication.isRoot && activity != null) { activity.handler.post(() => { - val intent = activity.getIntent - activity.finish() - startActivity(intent) + activity.deattachService + activity.attachService }) } case _ =>