Entire react native app showing on lockscreen Entire react native app showing on lockscreen

Entire react native app showing on lockscreen

If you’ve encountered the issue of your entire React Native app appearing on the lock screen and need a solution to restrict certain screens, you’re not alone. This problem often arises in scenarios where specific functionality, like a call app, should be available on the lock screen while the rest of the app remains hidden. The provided code snippet in MainActivity.java attempts to address this by using the FLAG_SHOW_WHEN_LOCKED flag.

However, it’s essential to note that FLAG_SHOW_WHEN_LOCKED is deprecated in API level 27, as per the Android documentation. To address this deprecation and find a more modern solution, developers can turn to third-party libraries, one of which is react-native-keep-awake.


The lines of code provided in MainActivity.java utilize the now-deprecated FLAG_SHOW_WHEN_LOCKED. While this approach may have worked previously, it is no longer the recommended method for achieving the desired lock screen behavior. Developers are encouraged to adopt more up-to-date solutions to ensure compatibility with the latest Android versions.

Introducing react-native-keep-awake

As an alternative to FLAG_SHOW_WHEN_LOCKED, developers can leverage the capabilities of react-native-keep-awake. This library provides a fork for the FLAG_SHOW_WHEN_LOCKED solution, addressing the deprecation issue and offering a more sustainable approach for keeping certain screens active on the lock screen.

Implementation Guide

Follow these steps to integrate and use react-native-keep-awake in your React Native project:

npm install --save https://github.com/ShahilMangroliya/react-native-keep-awake.git

Once installed, you can import the module into your code and utilize its functions as follows:

                import KeepAwake from 'react-native-keep-awake';

                KeepAwake.activate(); // Enable lock screen functionality
                // ... Your code for lock screen behavior ...

                KeepAwake.deactivate(); // Disable lock screen functionality

By following these steps, you can effectively manage the lock screen behavior of your React Native app, ensuring that only specific screens have the desired functionality without affecting the entire application.