Android Question UserClosed parameter behaviour changed in Android 12?

agraham

Expert
Licensed User
Longtime User
The UserClosed parameter in Sub Activity_Pause (UserClosed As Boolean) used to be True if the Back key was pressed by the user. While chasing down an anomaly in a new very simple app I have found that ,whereas this is still true in Android 10 and 11, it is not so in Android 12.

It seems that in Android 12 pressing the Back key causes UserClosed to be False unless a Sub Activity_KeyPress is present. when it is True. There doesn't need to be any code in Sub Activity_KeyPress, it just needs to be declared.

Is this a change in Android 12 or a bug in B4A?
 

Attachments

  • BackTest.zip
    9.1 KB · Views: 91
Last edited:

drgottjr

Expert
Licensed User
Longtime User

Root launcher activities are no longer finished on Back press​

Android 12 changes the default handling of the system Back press on launcher activities that are at the root of their tasks. In previous versions, the system would finish these activities on Back press. In Android 12, the system now moves the activity and its task to the background instead of finishing the activity. The new behavior matches the current behavior when navigating out of an app using the Home button or gesture.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Found it! If there is a Sub Activity_KeyPress this is called which checks for the Back key and calls Activity.Finish if Activity_KeyPress doesn't return True to swallow the event.
Java:
        public boolean runDirectly(int i) {
            Boolean bool = (Boolean) main.processBA.raiseEvent2(main.this._activity, false, "activity_keypress", false, Integer.valueOf(i));
            if (bool == null || bool.booleanValue()) {
                return true;
            }
            if (i != 4) {
                return false;
            }
            main.this.finish();
            return true;
        }
    }
I think this is a bit unsatisfactory that the presence of a particular Sub changes the behaviour of an app in an unpredictable manner. Apps that, without a Sub Activity_KeyPress, use UserClosed to determine whether the user pressed the Back key and re-initialise various things to reset the UI now behave differently under Android 12 than previously. This was my scenario when my new app worked as expected on one phone and not on another. I think Erel needs to put his thinking cap on as to whether to retain the previous behaviour.
 
Upvote 0
Top