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.