From 9b29779be691c9376bcb616a28902818626c292f Mon Sep 17 00:00:00 2001 From: zt515 Date: Mon, 12 Jun 2017 18:10:31 +0800 Subject: [PATCH] Fix: Some crashes after jumping to SettingsActivity --- app/src/main/java/io/neoterm/ui/NeoTermActivity.kt | 14 ++++++++------ .../de/mrapp/android/tabswitcher/TabSwitcher.java | 6 +++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/neoterm/ui/NeoTermActivity.kt b/app/src/main/java/io/neoterm/ui/NeoTermActivity.kt index 9e0eb2d..caafbfc 100644 --- a/app/src/main/java/io/neoterm/ui/NeoTermActivity.kt +++ b/app/src/main/java/io/neoterm/ui/NeoTermActivity.kt @@ -10,7 +10,6 @@ import android.support.v4.view.OnApplyWindowInsetsListener import android.support.v4.view.ViewCompat import android.support.v7.app.AppCompatActivity import android.support.v7.widget.Toolbar -import android.util.Log import android.view.KeyEvent import android.view.View import android.widget.ImageButton @@ -60,6 +59,14 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection { tabSwitcher .setToolbarNavigationIcon(R.drawable.ic_add_box_white_24dp, createAddSessionListener()) tabSwitcher.inflateToolbarMenu(R.menu.tab_switcher, createToolbarMenuListener()) + + val serviceIntent = Intent(this, NeoTermService::class.java) + startService(serviceIntent) + bindService(serviceIntent, this, 0) + } + + override fun onResume() { + super.onResume() tabSwitcher.addListener(object : TabSwitcherListener { private var tabSwitcherButtonInited = false @@ -96,7 +103,6 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection { } override fun onTabRemoved(tabSwitcher: TabSwitcher, index: Int, tab: Tab, animation: Animation) { - Log.e("NeoTerm", "onTabRemoved " + tab.toString()) if (tab is TermTab) { tab.termSession?.finishIfRunning() removeFinishedSession(tab.termSession) @@ -108,10 +114,6 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection { override fun onAllTabsRemoved(tabSwitcher: TabSwitcher, tabs: Array, animation: Animation) { } }) - - val serviceIntent = Intent(this, NeoTermService::class.java) - startService(serviceIntent) - bindService(serviceIntent, this, 0) } override fun onDestroy() { diff --git a/chrome-tabs/src/main/java/de/mrapp/android/tabswitcher/TabSwitcher.java b/chrome-tabs/src/main/java/de/mrapp/android/tabswitcher/TabSwitcher.java index 37ea16e..bf201a8 100755 --- a/chrome-tabs/src/main/java/de/mrapp/android/tabswitcher/TabSwitcher.java +++ b/chrome-tabs/src/main/java/de/mrapp/android/tabswitcher/TabSwitcher.java @@ -1416,7 +1416,11 @@ public class TabSwitcher extends FrameLayout implements TabSwitcherLayout, Model TabSwitcherState savedState = new TabSwitcherState(superState); savedState.layoutPolicy = layoutPolicy; savedState.modelState = new Bundle(); - Pair pair = layout.detachLayout(true); + + Pair pair = null; + if (getCount() > 0) { + pair = layout.detachLayout(true); + } if (pair != null) { savedState.modelState