简体   繁体   English

API 19 Android中的OnNewIntent

[英]OnNewIntent in API 19 Android

I would like to recover the android intent my activity is launched with. 我想恢复我启动活动的android意图。

My activity, tested in API 19 (KitKat), besides the main intent, has the following intent filter and parameters: 我的活动在API 19(KitKat)中进行了测试,除主要意图外,还具有以下意图过滤器和参数:

        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. 但是,当我在活动运行时打开SVG文件时,它无法处理新的意图。 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 结合以下参数,进行6种配置

android:finishOnTaskLaunch="true" or "false"

But none of them make the onNewIntent function to be called when I open a SVG with my application. 但是当我用我的应用程序打开SVG时,它们都没有使onNewIntent函数被调用。 Instead, it displays the previous state (onPause and onResume are called as expected, and onCreate is called instead). 而是显示先前的状态(按预期方式调用了onPause和onResume,而是调用了onCreate)。

The only workaround I found was to cal the finish() function from withing the onPause() method, so that it effectively terminates the application. 我发现的唯一解决方法是使用onPause()方法来对finish()函数进行校准,以使其有效地终止应用程序。 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. 该博客解释说,我应该使用“ singleTop”,但在我的情况下不起作用。
  • This SO question does not have any answer. 这样的问题没有任何答案。
  • This famous SO question describes the set-up of the intent. 这个著名的SO问题描述了意图的设置。 But in my case, I do not create the intent myself, android does. 但就我而言,我不会自己创建意图,而android是。

For the moment, my program works well and loads SVG as I wanted. 目前,我的程序运行良好,可以根据需要加载SVG。 Some points about my configuration (maybe it can help) 关于我的配置的一些要点(也许可以帮上忙)

  • I am targeting Android API 15. I gave up with the 19. 我的目标是Android API15。我放弃了19。
  • I use android:finishOnTaskLaunch="true" in the AndroidManifest.xml 我在AndroidManifest.xml使用android:finishOnTaskLaunch="true"
  • I do not call finish() in the onPause() method 我没有在onPause()方法中调用finish()
  • OnNewIntent is never called, but the onCreate method is called which parse the new intent. 永远不会调用OnNewIntent ,但是会调用解析新意图的onCreate方法。
  • 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM