onNewIntent not called on Widows subsystem for Android

Anonymous
2023-04-03T18:42:11.0466667+00:00

I sideloaded one of the existing Android apps on Windows subsystem for Android(WSA) but it behaves differently on WSA as compared to Android OS. The activity is created which then opens a web browser. The browser redirects back to the app. On Android OS, the "onNewIntent" is called on redirection but on WSA the activity is getting created again(i.e., onCreate is called). In manifest file of the app, the launchMode is set to "singleTask" so I would expect "onNewIntent" to be called on WSA too.

android:launchMode="singleTask"

Is this a known WSA issue? Is there a recommended solution?

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,429 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,011 Reputation points
    2023-04-04T15:29:14.6933333+00:00
    Hello there,
    
    onNewIntent is only called if the activity is already open, It won't be called if the Activity is not open.
    
    This means that if your activity was closed, it will start normally and onCreate will be called. You can pass a flag in your intent that tells your Activity that it was started from notification, then you find that flag in your onCreate and if it exists, you call the same functions as you did in onNewIntent():
    
    val intent = Intent(applicationContext, HomeActivity::class.java).apply {
        flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP
        putExtra("Id", Id)
        putExtra("notificationIntent", true);
    }
    
    Hope this resolves your Query !!
    
    --If the reply is helpful, please Upvote and Accept it as an answer--
    
    0 comments No comments