Search code examples
androidandroid-notificationsfreezelockscreenbackground-service

App screen is freezes when It is opened from background service and phone screen is locked


I am opening my app from background when it receives a notification. For this I am using a service. Whenever my app is in background and a new notification comes, app will open automatically. It is working fine. But when app is in background and phone screen is locked, now when a notification will come, it will show on screen(locked screen) and when user will open phone lock, my app's screen will be visible but screen will not responding, screen colour will also be like greyish layout on it.

To open app I am using a service, code is:

Intent serviceIntent = new Intent(getApplicationContext(), NewTaskService.class);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                        startForegroundService(serviceIntent);
                    } else {
                        startService(serviceIntent);
                    }

In NewTaskService Class I am opening my app.

The resulted screen image when app is opened with notification from on lock screen is attached.


Solution

  • Basically, it was due to a dialog box. When app is opened and user unlocks mobile screen, dialog box disappears but screen is visible like there is a dialog box. Screen was not freezing or stucking, also the screen was greyish type due to that dialog box.

    Because in such scenario dialog box view disappears.