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

Camera resource preemption in multi-window mode causing app crash #704

Open
Huimilia opened this issue Jan 10, 2025 · 1 comment
Open

Camera resource preemption in multi-window mode causing app crash #704

Huimilia opened this issue Jan 10, 2025 · 1 comment

Comments

@Huimilia
Copy link

Issue Description
In multi-window mode, when an application is running in full-screen mode and using the camera, if another application is opened in floating window mode and takes control of the camera resource, a focus switch may cause the original application’s camera resource to fail to recover properly. When the user switches back to the original application, the camera resource should be restored for use. However, in practice, the application interface may freeze or crash, and the application needs to be restarted to recover normal functionality.

Expected Behavior
In multi-window mode, applications using the camera resource should be able to smoothly transfer camera resource control during focus changes:

  • When the application loses focus, it should suspend its use of the camera resource.
  • When the application regains focus, it should be able to resume access to the camera resource without affecting the user experience.

Suggested Solution
It is recommended to add appropriate logic in the onWindowFocusChanged method to handle the camera resource allocation during focus changes. This method is triggered when the Activity's window focus state changes, including when the application starts for the first time or when returning from another Activity. By checking the hasFocus parameter, the application can determine whether it has regained focus, and if so, it should attempt to reinitialize or request access to the camera resource. In multi-window mode, adding this logic can help better coordinate the use of camera resources, thereby improving the application’s stability and user experience in multi-tasking scenarios. Below is an example of pseudocode:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    if (hasFocus) {
        // Activity has gained focus
        if (isInMultiWindowMode()) {
            Log.i("CameraHandler", "Attempting to reinitialize camera...");
            try {
                // Request camera resource again 
            } catch (Exception e) {
                Log.e("CameraHandler", "Error handling camera during focus change: " + e.getMessage());
            }
        }
    } else {
        // Activity has lost focus
        // Optionally pause camera usage and release resources here
    }
}

By incorporating this logic during focus changes, it can effectively reduce camera resource conflicts in multi-window mode and enhance the application's stability and reliability.

@hillelcoren
Copy link
Member

Hi, when do you use the camera with the Windows app?

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

No branches or pull requests

2 participants