Search code examples
javaandroidkotlinandroid-activitypush-notification

How not to interrupt the current process in the application when the user clicks on push?


on one screen in my application, I am recording audio.

Scenario: User records audio on this screen. A push comes from our application. The user clicks on this push and another push processing activity is launched.

Result: The user loses his session.

Question: what are the options for handling this case so that the user does not lose his session? Ideally, before switching to a new activity, the application would ask the user if he is sure that he wants to go to another screen, because the session will be lost. But how to track it?

Thanks a lot for your advice


Solution

  • The best solution I have found is to clear all old push notifications in the notification shade when going to the recording screen.

    val notificationsManager = getSystemService<Any>(Context.NOTIFICATION_SERVICE) as NotificationManager?
    notificationsManager!!.cancelAll()
    

    Further during the recording, if a push notification arrives, I receive this in my service inherited from FirebaseMessagingService in onMessageReceived().

    If the recording screen is currently open, I do not show a notification in the notification shade. But I show a widget on the recording screen with the push text and if the user presses it I ask if the user wants to go to another screen because the recording will end.

    I hope my experience helps someone. Similarly implemented in Intercom