0

When my application is on background or killed I would like to send some data like title or content using intent. At my onNewIntent() I receive nulls when my app is killed/on background. Why? Also I have read that handleIntent(intent: Intent) method is always call nevertheless I don't have access to data like title or content in handleIntent method to use it.

What is an alternative to get data even if app is killed or is on background? How to retrieve data such as title or content and use i.e. handleIntent?

    private fun buildNotification(title: String, content: String) =
    NotificationCompat.Builder(this, channelId).apply {

        val intent = Intent(applicationContext, MainActivity::class.java)
        intent.putExtra("notificationData", content)
        intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
        val pendingIntent = PendingIntent.getActivity(
            applicationContext,
            1,
            intent,
            FLAG_UPDATE_CURRENT
        )
    [...]
}

As well I understand buildNotification method is not triggered when app is killed/on background.

chrisu.chrisu
  • 119
  • 2
  • 14
  • I think this is the answer that you need https://stackoverflow.com/questions/30525784/android-keep-service-running-when-app-is-killed – Manuel Mato Dec 22 '21 at 17:58
  • I think not exactly, because I need to collect data which is sent from backend let's say in title or content of notification but none of methods are trigerred i.e. onMessageReceiveed – chrisu.chrisu Dec 22 '21 at 18:12

0 Answers0