Overview
On some Android devices the screen of an app can stay black after a system window has closed on top of it: a permission prompt, a dialog or the on-screen keyboard. The app is still running, but nothing is drawn until the next change.
KlugBlackScreen redraws the app's view as soon as such a window closes. Switched on once at start, it works automatically in the background. For special cases it can also be triggered directly.
Features
- Automatic mode: switch on once, it redraws after every system window
- Manual redraw for special cases
- A gentle redraw without flicker, and a stronger one for stubborn cases
- Does nothing on other platforms, so the code can stay in a cross-platform app
Supported platforms
Android arm64 · armv7
Getting started
Add the extension to your application descriptor:
<extensions>
<extensionID>com.klug.blackscreen</extensionID>
</extensions>
Code examples
Three flows. Every call returns at once and does its work on the Android UI thread; on other platforms the calls do nothing.
1 · Switch on once at start
import com.klug.blackscreen.BlackScreen; // once, in the constructor of your main class: from now on the view is redrawn // whenever the app window gets the focus back, after a permission prompt, // a dialog, the keyboard or another activity BlackScreen.getInstance().startAuto(); // a second call has no effect // iOS, macOS and desktop: isSupported is false and every call does nothing, // so no platform check is needed. stopAuto() switches it off again (rarely needed).
2 · Redraw after a system window closes
// call this from the result handler of any system window that covered the app: // a permission prompt, a share sheet, a native dialog, a sign-in page function onSystemWindowClosed():void { BlackScreen.getInstance().fix(); // redraw once, no flicker } // example: your own permission flow reports back myPermissionFlow.onResult = function( granted:Boolean ):void { onSystemWindowClosed(); if ( granted ) startCamera(); else showPermissionHint(); };
3 · Stronger redraw when returning to the app
import flash.desktop.NativeApplication; import flash.events.Event; // back from another activity (share sheet, browser, system settings) and fix() // is not enough on a given runtime build: the stronger redraw may flicker once NativeApplication.nativeApplication.addEventListener( Event.ACTIVATE, function( e:Event ):void { BlackScreen.getInstance().fixHard(); }); // the first fixHard() replaces the launch background of the window with plain white, // so the short toggle does not show the splash image
API overview
| BlackScreen.getInstance() | Returns the single instance. |
| isSupported | True on Android; false on iOS, macOS and desktop, where every call does nothing. |
| startAuto() | Redraws automatically whenever the app window gets the focus back, for example after a system window closes. Call once at start; a second call has no effect. |
| stopAuto() | Stops the automatic mode. |
| fix() | Redraws the view once, without flicker. |
| fixHard() | Stronger redraw for stubborn cases, with a short flicker. The first call replaces the launch background of the window with plain white. |
Requirements
| AIR SDK | 51.x (HARMAN) |
| Android | Android 6.0 (API 23) or later |
| Permissions | None |