Optimize timer code.
Apparently onStop will be executed when the screen goes off.
This commit is contained in:
@@ -475,15 +475,12 @@ class Shadowsocks
|
||||
} else {
|
||||
TrafficMonitor.reset()
|
||||
}
|
||||
val pm = getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager]
|
||||
if (pm.isScreenOn) {
|
||||
val trafficStat = getString(R.string.stat_summary).formatLocal(Locale.ENGLISH,
|
||||
TrafficMonitor.getTxRate, TrafficMonitor.getRxRate,
|
||||
TrafficMonitor.getTxTotal, TrafficMonitor.getRxTotal)
|
||||
handler.post(() => {
|
||||
preferences.findPreference(Key.stat).setSummary(trafficStat)
|
||||
})
|
||||
}
|
||||
val trafficStat = getString(R.string.stat_summary).formatLocal(Locale.ENGLISH,
|
||||
TrafficMonitor.getTxRate, TrafficMonitor.getRxRate,
|
||||
TrafficMonitor.getTxTotal, TrafficMonitor.getRxTotal)
|
||||
handler.post(() => {
|
||||
preferences.findPreference(Key.stat).setSummary(trafficStat)
|
||||
})
|
||||
}
|
||||
}
|
||||
timer = new Timer(true)
|
||||
|
||||
Reference in New Issue
Block a user