How to Convert XAPK to APK How to Convert XAPK to APK

How to cold start a React Native app over device lock screen?

If you’re developing a Voice over Internet Protocol (VoIP) app using React Native and facing challenges with cold starting the app when the device is locked, this article provides a solution to ensure a smoother user experience.

The Challenge

While building your VoIP app, you’ve successfully managed to bring the application to the foreground upon receiving push notifications in various scenarios. However, an issue arises when the device is locked, and the app is killed. In this case, the app starts but doesn’t appear over the lock screen, requiring users to unlock their phones to access the app.

The Code

Examining your provided code snippets, it’s evident that the logic for handling incoming push notifications is well-implemented. To address the specific scenario of a locked device and a killed app, additional adjustments are needed.


// MainActivity in AndroidManifest.xml
<activity android:name=".MainActivity"
    ...
    android:showWhenLocked="true"
    android:turnScreenOn="true"
>

Make sure to include the above attributes in your MainActivity declaration within the AndroidManifest.xml file.


// Permission in AndroidManifest.xml
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />

Include the permission for USE_FULL_SCREEN_INTENT to enhance the app’s behavior when starting from a cold state.

Explanation

Setting android:showWhenLocked="true" ensures that your app’s activity is visible over the lock screen. Meanwhile, android:turnScreenOn="true" instructs the system to turn on the screen when launching the app, providing immediate visibility to users even if the device is locked.

Additionally, requesting the USE_FULL_SCREEN_INTENT permission allows your app to use full-screen intents, further improving the display of notifications and interactions when the device is locked.

Conclusion

By implementing the suggested changes in your AndroidManifest.xml file, you can enhance the cold start behavior of your React Native VoIP app, ensuring a seamless experience for users, even when the device is locked and the app is launched from a killed state.