Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Event.DEACTIVATE does not fire when opening task list #2772

Closed
takazawa-gg opened this issue Aug 18, 2023 · 24 comments
Closed

[Android] Event.DEACTIVATE does not fire when opening task list #2772

takazawa-gg opened this issue Aug 18, 2023 · 24 comments

Comments

@takazawa-gg
Copy link

Event.DEACTIVATE does not seem to fire when opening the task list on a device with Android 13.

In our app, we were trying to set fps to 0 or save data when deactivate was detected, but in Android 13, the app animation continues to play even when the task list is opened.

Animation stops on devices up to Android 12.

Can you confirm if this is a specification or unexpected behavior?

We are checking the operation with AIR SDK 50.2.3.2.

@ajwfrost
Copy link
Collaborator

Hi

We're not able to reproduce this with a basic SWF on Android 13, we're getting the Event.DEACTIVATE message when we just push up the bottom of the screen to display the task list...

Are you able to confirm what handset(s) you've tried this on, and maybe provide a quick test file that reproduces the issue?

thanks

@takazawa-gg
Copy link
Author

takazawa-gg commented Aug 25, 2023

The device we tested was the Pixel 6a.
Unfortunately this was the only device available to us that could be updated to Android 13.

We also took a video showing the problem.
The device on the left is a Pixel 6a (Android 13) and the device on the right is an AQUOS zero2 (Android 10).

android_task_list.mp4

Attached is a simple project used for testing.

AIR_Test.zip

@takazawa-gg
Copy link
Author

On Pixel 6a, where we observed this problem, we found that OnApplicationPause() was not being called and data saving was not happening at the timing we expected, even for Unity apps.

Then I found the following post.
In Unity, it says that it is a specification that OnPause is not called in the Task List screen in Pixel 3.

https://issuetracker.unity3d.com/issues/android-onapplicationpause-true-is-not-called-when-going-to-recent-apps-on-pixel-3

And taking a cue from this post, I incorporated OnApplicationFocus() and the Unity app now receives a notification that it has lost focus on the Task List screen.

https://gamedev.stackexchange.com/questions/191550/saving-settings-when-exiting-the-application

I thought that using the same Focus event in AIR would solve the problem, but the documentation below says that the event for losing focus in AIR is "deactivate".

https://help.adobe.com/ja_JP/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7e07.html

Hmmm. Is there any way to do this?

@ajwfrost
Copy link
Collaborator

Thanks for the investigations there .. so it looks like there's an alternative Android event that's being sent, that we'd need to hook into to make the deactivate/activate events fire in these scenarios. We'll see if we can check and incorporate this (and will see about testing on a Pixel 3 or 6a..)

@takazawa-gg
Copy link
Author

We are going to start working on updating about 90-110 apps next week to be compatible with Android 13 (API Level 33).

If it were not so difficult to deal with the new Focus events, I would prefer to use the AIR SDK with it's updated version.

It would be great to get information by next week on the status of the confirmation and the release schedule.

@ajwfrost
Copy link
Collaborator

Okay thanks -> it looks like we can handle this by adding a listener for onTopResumedActivityChanged

We should be able to do this fairly swiftly, the logic to handle both this and onPause/onResume would be straightforward.. there's a plan to get a patch release for Android out by the end of next week so I'll get this added/tested to target that.

thanks

@takazawa-gg
Copy link
Author

Thanks for the reply.
I look forward to your update!

@marchbold
Copy link
Collaborator

Resolved in 50.2.3.5

@takazawa-gg
Copy link
Author

I tried 50.2.3.5.
My Pixel 6a still does not generate interruption events.
Do I need to listen for some other new event that is not DEACTIVATE?

@marchbold marchbold reopened this Sep 11, 2023
@ajwfrost
Copy link
Collaborator

@takazawa-gg it should still be the 'deactivate' event.. if you're not receiving that, then either we've got a bug still, or the device isn't sending the expected lifecycle event.

Do you have a Pixel 6a you can try this out on? We were using a 6a from AWS Device Farm and it worked okay there, but there may be differences in the software builds I guess. If you have Android Studio, would you be able to do some testing/debugging for us to see what may be happening?

If you are able to build a test app that just listens out for the activate/deactivate events, and does a "trace" output or similar (or pauses the animation?) - in debug mode - then could you package this using the command:

adt -package -target android-studio-debug ASProjectFolder application.xml test.swf

This should create a folder in which there's an Android Studio project that you can then open in Android Studio. If you then open the app/java main class (your application ID as the package name, and then "AIRAppEntry") - you should be able to then add a bit of Java within this class:

    @Override
    public void onTopResumedActivityChanged (boolean isTopResumedActivity)
    {
        Log.i("TESTING_AIR", "ON TOP ACTIVITY -> " + isTopResumedActivity);
        super.onTopResumedActivityChanged(isTopResumedActivity);
    }

Then if you connect your Pixel 6a and hit the "debug" button, it should build this and deploy it onto your device. You can then hopefully see whether the above function is being called when you bring up the task list.

thanks

@takazawa-gg
Copy link
Author

I tried debugging.
It seems that onTopResumedActivityChanged is not being called.
I also tried onWindowFocusChanged, which is called.

public class AIRAppEntry extends AppEntry {
    @Override
    public void onTopResumedActivityChanged(boolean isTopResumedActivity)
    {
        Log.i("TESTING_AIR", "ON TOP ACTIVITY -> " + isTopResumedActivity);
        super.onTopResumedActivityChanged(isTopResumedActivity);
    }
    
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        Log.i("TESTING_AIR", "onWindowFocusChanged -> " + hasFocus);
        super.onWindowFocusChanged(hasFocus);
    }
}
IMG_7172_10.mp4

Screenshot_20230912-104254

@takazawa-gg
Copy link
Author

@ajwfrost
Did you find out anything from the debugging information?
We have a reproducible environment and can collect additional information. Please contact us if needed.

@ajwfrost
Copy link
Collaborator

Hi

We have some concerns with using the window focus event to determine whether the application is active or not .. as the window focus will seemingly also be triggered in a number of other situations where you actually would want the AIR application to continue running. So we may have to look at a different option here..

We can do a test build though and upload the ADT jar file that would be able to make a change to handle your scenario above, it would be good if you're able to then see what side-effects there are (e.g. when browsing for files or showing any kind of pop-up messages, requesting permissions for things, etc).

I'm wondering whether a better option - for the longer term - would be to have NativeWindow support on mobiles, as this then would be a property/event for the window itself rather than the application. The application/activity here is still very much active and in the foreground, from Android's lifecycle perspective, even though the window hasn't got the input focus any more...

thanks

@itlancer
Copy link

@ajwfrost, about NativeWindow support on mobiles. I think it's good idea.
It also help to support smartphone/tablets with a folding screen: #2799
Also it could allow to support Android devices with multiple displays:
https://source.android.com/docs/core/display/multi_display
Such as smartphones/tablets, POS terminal and professional devices with multiple physical screens such as https://www.hp.com/us-en/shop/tech-takes/hp-engage-one-prime-retail-pos-system

@ajwfrost
Copy link
Collaborator

@itlancer yes that kind of thing was also at the back of my mind too :-) Android (and to a lesser extent, iPadOS) is starting to move towards providing a more "desktop" type experience!

@takazawa-gg
Copy link
Author

@ajwfrost
Thanks for the reply.

The primary use of the focus event in our app is to trigger a data save.
We also do regular saves, but we believe that the best way to save the most recent data is to save at the point where the user may be about to leave the application.
For many Android devices, saving the data in the deactivate event works well, but unfortunately on the Pixel, the process terminates before the save process is complete.

For this purpose, it would serve its purpose if it could receive independent Event.FOCUS events. What do you think?

@takazawa-gg
Copy link
Author

@ajwfrost
Hi,

What happened to this issue?

If a focus event is not available, we must consider an alternative approach.
If possible, we would like to use focus events, as we would like to keep the logic the same internally with our Unity apps.

Please consider.

@ajwfrost
Copy link
Collaborator

Hi @takazawa-gg - apologies for the delay, we had actually created a test build with the Android window focus event also going in to trigger the activate/deactivate events. So perhaps until we have a separate NativeWindow support per the above comments, this would work instead?
Please check with the latest AIR SDK plus the below adt.jar file (extracted from the zip and put into the "lib" folder)
adt.zip

thanks

@takazawa-gg
Copy link
Author

@ajwfrost
By using the adt.jar that was provided, we were able to confirm that the expected behavior was achieved.
activate/deactivate is called on Pixel, Galaxy and Xperia without any problem!
I appreciate it very much.

P.S. I hope the recent Unity Fee issue will bring AIR back into the spotlight!

@bobaoapae
Copy link

after update to latest air skd (that address this issue) my app get black screen when i do several actions on my android phone.

Some examples:
Take screenshot.
Swipe to show the notification bar.

go to task list and open app again remove the blackscreen and show the game again, but executing any of the examples above trigger blackscreen again.

@bobaoapae
Copy link

Rolling back to 50.2.3.5 resolve the problem.

@marchbold
Copy link
Collaborator

Just wanted to make a comment here, I don't believe the DEACTIVATE event should be dispatched when the application drawer / list is displayed. Most applications are expected to continue to run here on Android and a native application doesn't get the activity lifecycle "pause" event which I believe the deactivate event should mostly mimic.

@Mintonist
Copy link

Seems we need two different events for mentioned cases. And developer can decide which to use.

@marchbold
Copy link
Collaborator

Agreed, I think there should be some "focus" type event alongside the existing activate ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants