Prevent NullPointerException in onBackPressed

This crash seems to somehow only happen on Huawei and Xiaomi devices.
While fairly rare, it is the most common Catima crash currently logged
on Google Play Console (8 crashes over the last 28 days).

While I don't understand how this would happen, I think it should be
relatively safe to assume that if the searchview is null the user isn't
currently searching so running the normal back code should always be the
expected behaviour.
This commit is contained in:
Sylvia van Os
2022-11-16 21:42:52 +01:00
parent 28901487ff
commit 10498ce1a4

View File

@@ -425,7 +425,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
@Override
public void onBackPressed() {
if (!mSearchView.isIconified()) {
if (mSearchView != null && !mSearchView.isIconified()) {
mSearchView.setIconified(true);
return;
}