Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
android: Override MainActivity.invokeDefaultOnBackPressed, following …
Browse files Browse the repository at this point in the history
…Expo

This belatedly follows a change in Expo's template app,
templates/expo-template-bare-minimum. The change was made in
expo/expo@2a0079132, and we missed it in the Expo 44 upgrade (zulip#5441)
because Expo's upgrade guide forgot about it. See discussion of this
and other changes that were missed:
  https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Expo.2044.20small.20things/near/1452850

This seems to fix a bug I've observed on the office Android device
(Samsung Galaxy S9 running Android 9), where if I exit the app via
the back button, then re-enter the app, the state gets reset such
that we register for a new event queue.
chrisbobbe authored and BrandonNgoranNtam committed Nov 22, 2022
1 parent 90e7917 commit 63149ec
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions android/app/src/main/java/com/zulipmobile/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.zulipmobile

import android.os.Build
import android.content.Intent
import android.os.Bundle
import android.webkit.WebView
@@ -91,4 +92,23 @@ open class MainActivity : ReactActivity() {
}
super.onNewIntent(intent)
}

/**
* Align the back button behavior with Android S
* where moving root activities to background instead of finishing activities.
* @see <a href="https://developer.android.com/reference/android/app/Activity#onBackPressed()">onBackPressed</a>
*/
override fun invokeDefaultOnBackPressed() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
if (!moveTaskToBack(false)) {
// For non-root activities, use the default implementation to finish them.
super.invokeDefaultOnBackPressed()
}
return
}

// Use the default back button implementation on Android S
// because it's doing more than {@link Activity#moveTaskToBack} in fact.
super.invokeDefaultOnBackPressed()
}
}

0 comments on commit 63149ec

Please sign in to comment.