Question

I would like to recover the android intent my activity is launched with.

My activity, tested in API 19 (KitKat), besides the main intent, has the following intent filter and parameters:

        android:alwaysRetainTaskState="false"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:screenOrientation="landscape"
        android:configChanges="orientation|keyboardHidden|screenSize">
         <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:scheme="file" />
            <data android:mimeType="*/*" />
            <data android:pathPattern=".*\\.svg" />
            <data android:host="*" />
        </intent-filter>

But when I open a SVG file while the activity was running, it does not handle the new intent. I tried the following combinations, launched the activity,

android:launchMode="singleTask"

android:launchMode="standard"

android:launchMode="singleTop"

combined with the following parameter, that makes 6 configurations

android:finishOnTaskLaunch="true" or "false"

But none of them make the onNewIntent function to be called when I open a SVG with my application. Instead, it displays the previous state (onPause and onResume are called as expected, and onCreate is called instead).

The only workaround I found was to cal the finish() function from withing the onPause() method, so that it effectively terminates the application. I don't understand what is going on because it was working last year before I changed targets.

What is the required configuration to access the calling intents each time?

Related questions without answers to mine:

  • This blog explains that I should use "singleTop" but it is not working in my case.
  • This SO question does not have any answer.
  • This famous SO question describes the set-up of the intent. But in my case, I do not create the intent myself, android does.
Was it helpful?

Solution

For the moment, my program works well and loads SVG as I wanted. Some points about my configuration (maybe it can help)

  • I am targeting Android API 15. I gave up with the 19.
  • I use android:finishOnTaskLaunch="true" in the AndroidManifest.xml
  • I do not call finish() in the onPause() method
  • OnNewIntent is never called, but the onCreate method is called which parse the new intent.
  • The content of the activity manifest is the following:

    <activity
      android:name="com.example.mypackage"
      android:launchMode="singleTop"
      android:finishOnTaskLaunch="true"
      android:alwaysRetainTaskState="false"
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
      android:screenOrientation="landscape"
      android:configChanges="orientation|keyboardHidden|screenSize">
      <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:scheme="file" />
        <data android:mimeType="*/*" />
        <data android:pathPattern=".*\\.svg" />
        <data android:host="*" />
      </intent-filter>
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top