From 10725c39cbd400d3c5bc06ad5e52c03a313ba7b7 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 9 Aug 2016 10:33:03 +0800 Subject: [PATCH] Check QsTile is null --- .../shadowsocks/ShadowsocksTileService.scala | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksTileService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksTileService.scala index ae7cdad039..bb74a8a86d 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksTileService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksTileService.scala @@ -25,24 +25,26 @@ final class ShadowsocksTileService extends TileService with ServiceBoundContext def trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) = () def stateChanged(state: Int, msg: String) { val tile = getQsTile - state match { - case State.STOPPED => - tile.setIcon(iconIdle) - tile.setLabel(getString(R.string.app_name)) - tile.setState(Tile.STATE_INACTIVE) - case State.CONNECTED => - tile.setIcon(iconConnected) - tile.setLabel(app.currentProfile match { - case Some(profile) => profile.name - case None => getString(R.string.app_name) - }) - tile.setState(Tile.STATE_ACTIVE) - case _ => - tile.setIcon(iconBusy) - tile.setLabel(getString(R.string.app_name)) - tile.setState(Tile.STATE_UNAVAILABLE) + if (tile != null) { + state match { + case State.STOPPED => + tile.setIcon(iconIdle) + tile.setLabel(getString(R.string.app_name)) + tile.setState(Tile.STATE_INACTIVE) + case State.CONNECTED => + tile.setIcon(iconConnected) + tile.setLabel(app.currentProfile match { + case Some(profile) => profile.name + case None => getString(R.string.app_name) + }) + tile.setState(Tile.STATE_ACTIVE) + case _ => + tile.setIcon(iconBusy) + tile.setLabel(getString(R.string.app_name)) + tile.setState(Tile.STATE_UNAVAILABLE) + } + tile.updateTile } - tile.updateTile } }