Skip to content

Android) add mechanics to resume application from background - #660

Open
hsdk123 wants to merge 1 commit into
mosra:masterfrom
hsdk123:androidcontext
Open

Android) add mechanics to resume application from background#660
hsdk123 wants to merge 1 commit into
mosra:masterfrom
hsdk123:androidcontext

Conversation

@hsdk123

@hsdk123 hsdk123 commented Jan 23, 2025

Copy link
Copy Markdown
Contributor

Currently, the application will crash if sent to the background and brought back to the foreground.
The following provides a mechanism to continue the application.

@mosra mosra left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, this is about handling the case where GL context isn't lost and just the window surface is, right? So it's not like existing GL objects become invalid afterwards.

I'll have to think how to expose this in a way that makes sense with other apps. I can imagine that for example on desktop with SDL/GLFW one might want to attach to some focusEvent() / blurEvent() as well, when the window gets active or inactive.

Comment on lines +222 to +223
/* Pause the context current */
CORRADE_INTERNAL_ASSERT_OUTPUT(eglMakeCurrent(_display, nullptr, nullptr, nullptr));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work if you kept the context current and just made it bound to no surface at all?

Suggested change
/* Pause the context current */
CORRADE_INTERNAL_ASSERT_OUTPUT(eglMakeCurrent(_display, nullptr, nullptr, nullptr));
/* Keep the GL context current but without any surface */
CORRADE_INTERNAL_ASSERT_OUTPUT(eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, _glContext));

Because I'm wondering if it's guaranteed that no app code gets executed between APP_CMD_LOST_FOCUS and APP_CMD_INIT_WINDOW. And if it does, it'd be probably good to have the GL context current.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested change, at least from my side, seems to work fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it's guaranteed that no app code gets executed between APP_CMD_LOST_FOCUS and APP_CMD_INIT_WINDOW

I'm not sure about there being a guarantee, but it's one of the reasons I added _application_has_valid_surface - such that the user has some info to branch on.

@mosra mosra added this to the 2025.0a milestone Jan 23, 2025
@hsdk123

hsdk123 commented May 24, 2025

Copy link
Copy Markdown
Contributor Author

@mosra did you find more time to look into this?

@mosra

mosra commented Jun 5, 2025

Copy link
Copy Markdown
Owner

Only partially, sorry -- so far I added the focusEvent() and blurEvent() to all apps in 7558bc7, in case you want to adapt this code to use these.

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.46%. Comparing base (e43eba6) to head (f9d1243).
⚠️ Report is 530 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #660   +/-   ##
=======================================
  Coverage   77.46%   77.46%           
=======================================
  Files         583      583           
  Lines       47828    47828           
=======================================
  Hits        37051    37051           
  Misses      10777    10777           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants