Repository: square/leakcanary
Issue: Crash when clicking the "n Leak Groups" button in ActionBar, after loading first report

### Description

LeakCanary 2.0-beta-3 crashes when the "n Leak Groups" button is pressed, after loading the first report.

### Steps to Reproduce

1. Use an Android 4.2 device
1. Run the library on an app that has a memory leak
2. Click the "Leaks" icon in the home screen, to view the Leak report
3. Click on "Latest: xxx" to view the first report
4. Press the Back button, to go back to the previous screen
5. Press the "n Leak Groups" button at the top left (or top right)
6. Observe the crash:

```java
E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1
        at java.util.ArrayList.remove(ArrayList.java:401)
        at leakcanary.internal.navigation.NavigatingActivity.goBack(NavigatingActivity.kt:111)
        at leakcanary.internal.navigation.NavigatingActivity.onOptionsItemSelected(NavigatingActivity.kt:137)
        at android.app.Activity.onMenuItemSelected(Activity.java:2612)
        at com.android.internal.widget.ActionBarView$4.onClick(ActionBarView.java:285)
        at android.view.View.performClick(View.java:4452)
        at android.view.View$PerformClick.run(View.java:18428)
        at android.os.Handler.handleCallback(Handler.java:725)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:176)
        at android.app.ActivityThread.main(ActivityThread.java:5365)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
        at dalvik.system.NativeStart.main(Native Method)
```

**Expected behavior:**

* No crash.
* Either exit out of the app
* Or disable the "n Leak Groups" button, like on other Android versions.

### Version Information

* LeakCanary version: LeakCanary 2.0-beta-3
* Android OS version: Android 4.2
* Gradle version: 5.1.1

### Additional Information

I believe the problem is in [this function](https://github.com/square/leakcanary/blob/724ed6fdf5d1bced571afce09e7c9202263b60a8/leakcanary-android-core/src/main/java/leakcanary/internal/navigation/NavigatingActivity.kt#L105):

```kotlin
fun goBack() {
    onCreateOptionsMenu = NO_MENU

    currentView.startAnimation(loadAnimation(this, R.anim.leak_canary_exit_backward))
    container.removeView(currentView)

    val latest = backstack.removeAt(backstack.size - 1)
    currentScreen = latest.screen
    currentView = currentScreen.createView(container)
    currentView.startAnimation(loadAnimation(this, R.anim.leak_canary_enter_backward))
    container.addView(currentView, 0)
    latest.restore(currentView)

    updateActionBar()
}

```

Perhaps try something like this:

```kotlin
fun goBack() {
    onCreateOptionsMenu = NO_MENU

    currentView.startAnimation(loadAnimation(this, R.anim.leak_canary_exit_backward))
    container.removeView(currentView)

    if (backstack.size > 0) {
        val latest = backstack.removeAt(backstack.size - 1)
        currentScreen = latest.screen
        currentView = currentScreen.createView(container)
        currentView.startAnimation(loadAnimation(this, R.anim.leak_canary_enter_backward))
        container.addView(currentView, 0)
        latest.restore(currentView)
        updateActionBar()
    }
}

```

Changed files:
leakcanary-android-core/src/main/java/leakcanary/internal/navigation/NavigatingActivity.kt

diff --git a/leakcanary-android-core/src/main/java/leakcanary/internal/navigation/NavigatingActivity.kt b/leakcanary-android-core/src/main/java/leakcanary/internal/navigation/NavigatingActivity.kt
index f53117e1c..a45ee811f 100644
--- a/leakcanary-android-core/src/main/java/leakcanary/internal/navigation/NavigatingActivity.kt
+++ b/leakcanary-android-core/src/main/java/leakcanary/internal/navigation/NavigatingActivity.kt
@@ -123,7 +123,9 @@ internal abstract class NavigatingActivity : Activity() {
     val actionBar = actionBar
         ?: // https://github.com/square/leakcanary/issues/967
         return
-    actionBar.setDisplayHomeAsUpEnabled(backstack.size > 0)
+    val homeEnabled = backstack.size > 0
+    actionBar.setDisplayHomeAsUpEnabled(homeEnabled)
+    actionBar.setHomeButtonEnabled(homeEnabled)
   }
 
   override fun onCreateOptionsMenu(menu: Menu): Boolean {