Skip to content

fix(android): defer wakelock toggle when no activity is attached W…#134

Open
sadaqatdev wants to merge 1 commit into
fluttercommunity:mainfrom
sadaqatdev:main
Open

fix(android): defer wakelock toggle when no activity is attached W…#134
sadaqatdev wants to merge 1 commit into
fluttercommunity:mainfrom
sadaqatdev:main

Conversation

@sadaqatdev
Copy link
Copy Markdown

@sadaqatdev sadaqatdev commented May 21, 2026

…akelock.toggle()/isEnabled() threw NoActivityException whenever they were called with no foreground activity attached (e.g. the app is backgrounded or mid lifecycle transition), surfacing as non-fatal crashes in apps that toggle the wakelock off the foreground path. Instead of throwing, the requested wakelock state is now tracked in Kotlin and re-applied once an activity (re)attaches — matching how the Windows/Linux/web implementations track state. The activity setter only re-asserts FLAG_KEEP_SCREEN_ON when wakelock was actually enabled, so it won't clear the flag for apps that set it on their own window. The now-unused NoActivityException class is removed. Bumps wakelock_plus to 1.6.2 and updates the CHANGELOG. Fixes #131, #102, #6.

fix(android): defer wakelock toggle when no activity is attached

Wakelock.toggle()/isEnabled() threw NoActivityException whenever they
were called with no foreground activity attached (e.g. the app is
backgrounded or mid lifecycle transition), surfacing as non-fatal
crashes in apps that toggle the wakelock off the foreground path.

Instead of throwing, the requested wakelock state is now tracked in
Kotlin and re-applied once an activity (re)attaches — matching how the
Windows/Linux/web implementations track state. The activity setter only
re-asserts FLAG_KEEP_SCREEN_ON when wakelock was actually enabled, so it
won't clear the flag for apps that set it on their own window. The
now-unused NoActivityException class is removed.

Bumps wakelock_plus to 1.6.2 and updates the CHANGELOG.

Fixes #131, #102, #6.

…lock.toggle()/isEnabled() threw NoActivityException whenever they were called with no foreground activity attached (e.g. the app is backgrounded or mid lifecycle transition), surfacing as non-fatal crashes in apps that toggle the wakelock off the foreground path. Instead of throwing, the requested wakelock state is now tracked in Kotlin and re-applied once an activity (re)attaches — matching how the Windows/Linux/web implementations track state. The activity setter only re-asserts FLAG_KEEP_SCREEN_ON when wakelock was actually enabled, so it won't clear the flag for apps that set it on their own window. The now-unused NoActivityException class is removed. Bumps wakelock_plus to 1.6.2 and updates the CHANGELOG. Fixes fluttercommunity#131, fluttercommunity#102, fluttercommunity#6.

fix(android): defer wakelock toggle when no activity is attached

  Wakelock.toggle()/isEnabled() threw NoActivityException whenever they
  were called with no foreground activity attached (e.g. the app is
  backgrounded or mid lifecycle transition), surfacing as non-fatal
  crashes in apps that toggle the wakelock off the foreground path.

  Instead of throwing, the requested wakelock state is now tracked in
  Kotlin and re-applied once an activity (re)attaches — matching how the
  Windows/Linux/web implementations track state. The activity setter only
  re-asserts FLAG_KEEP_SCREEN_ON when wakelock was actually enabled, so it
  won't clear the flag for apps that set it on their own window. The
  now-unused NoActivityException class is removed.

  Bumps wakelock_plus to 1.6.2 and updates the CHANGELOG.

  Fixes fluttercommunity#131, fluttercommunity#102, fluttercommunity#6.
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

Successfully merging this pull request may close these issues.

PlatformException(NoActivityException, dev.fluttercommunity.plus.wakelock.NoActivityException: wakelock requires a foreground activity, C

1 participant