diff --git a/mobile/src/main/scala/com/github/shadowsocks/TaskerActivity.scala b/mobile/src/main/scala/com/github/shadowsocks/TaskerActivity.scala index 944b27e9ec..733ae3e727 100644 --- a/mobile/src/main/scala/com/github/shadowsocks/TaskerActivity.scala +++ b/mobile/src/main/scala/com/github/shadowsocks/TaskerActivity.scala @@ -82,6 +82,11 @@ class TaskerActivity extends AppCompatActivity { override def onCreate(savedInstanceState: Bundle) { super.onCreate(savedInstanceState) + try taskerOption = TaskerSettings.fromIntent(getIntent) catch { + case _: Exception => + finish() + return + } setContentView(R.layout.layout_tasker) val toolbar = findViewById(R.id.toolbar).asInstanceOf[Toolbar] @@ -89,7 +94,6 @@ class TaskerActivity extends AppCompatActivity { toolbar.setNavigationIcon(R.drawable.ic_navigation_close) toolbar.setNavigationOnClickListener(_ => finish()) - taskerOption = TaskerSettings.fromIntent(getIntent) switch = findViewById(R.id.serviceSwitch).asInstanceOf[Switch] switch.setChecked(taskerOption.switchOn) val profilesList = findViewById(R.id.list).asInstanceOf[RecyclerView] diff --git a/mobile/src/main/scala/com/github/shadowsocks/utils/TaskerSettings.scala b/mobile/src/main/scala/com/github/shadowsocks/utils/TaskerSettings.scala index 20ded7c4fb..c256f5a877 100644 --- a/mobile/src/main/scala/com/github/shadowsocks/utils/TaskerSettings.scala +++ b/mobile/src/main/scala/com/github/shadowsocks/utils/TaskerSettings.scala @@ -30,8 +30,7 @@ object TaskerSettings { private val KEY_SWITCH_ON = "switch_on" private val KEY_PROFILE_ID = "profile_id" - def fromIntent(intent: Intent) = new TaskerSettings(if (intent.hasExtra(ApiIntent.EXTRA_BUNDLE)) - intent.getBundleExtra(ApiIntent.EXTRA_BUNDLE) else Bundle.EMPTY) + def fromIntent(intent: Intent) = new TaskerSettings(intent.getBundleExtra(ApiIntent.EXTRA_BUNDLE)) } class TaskerSettings(bundle: Bundle) {