0

I have configured one of my activities in my app to be be opened using a deep link like so:

<activity
        android:name=".ui.barcodescanner.BarcodeScannerActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:host="com.company"
                android:scheme="http"
                android:pathPrefix="/myapp"/>
        </intent-filter>
    </activity>

This works as expected (my app launches with the correct activity) when chrome redirects to http://com.mycompany/myap on an API 27 Pixel 2 XL emulator. But I get the following error when I run it on my API 29 OnePlus 6:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.android.myapp/com.company.android.myapp.ui.login.IONLoginActivity}: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3037)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6863)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
    at android.app.ContextImpl.startActivity(ContextImpl.java:915)
    at android.app.ContextImpl.startActivity(ContextImpl.java:891)
    at android.content.ContextWrapper.startActivity(ContextWrapper.java:379)
    at com.infor.authentication.AuthenticationManager.loadWebView(AuthenticationManager.java:712)
    at com.infor.authentication.AuthenticationManager.showAuthenticationDialog(AuthenticationManager.java:1810)
    at com.infor.authentication.AuthenticationManager.validateValuesAndStoreValues(AuthenticationManager.java:512)
    at com.infor.authentication.AuthenticationManager.initiateAuthentication(AuthenticationManager.java:460)
    at com.company.android.myapp.ui.login.IONLoginViewModel.authenticateWithION(IONLoginViewModel.java:26)
    at com.company.android.myapp.ui.login.IONLoginActivity.onCreate(IONLoginActivity.java:36)
    at android.app.Activity.performCreate(Activity.java:7149)
    at android.app.Activity.performCreate(Activity.java:7140)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3017)

Why is this?

shyam
  • 1,348
  • 4
  • 19
  • 37
  • Did you read this " from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. " ? – Artem Mar 07 '19 at 10:02
  • and did you read this https://stackoverflow.com/questions/3918517/calling-startactivity-from-outside-of-an-activity-context before ? – Artem Mar 07 '19 at 10:03
  • @Artem the point is, I am not creating the intent to open the activity. Chrome is generating the intent based on the url that it is presented with. Atleast, that is my understanding of it. So I cannot hope to add that flag in the intent, can I? – shyam Mar 07 '19 at 10:13

0 Answers0