【问题标题】:OnNewIntent in API 19 AndroidAPI 19 Android 中的 OnNewIntent
【发布时间】:2014-01-24 22:29:40
【问题描述】:

我想恢复启动我的活动的 android 意图。

我的活动在 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>

但是,当我在 Activity 运行时打开 SVG 文件时,它不会处理新的 Intent。 我尝试了以下组合,启动了活动,

android:launchMode="singleTask"

android:launchMode="standard"

android:launchMode="singleTop"

结合以下参数,构成6种配置

android:finishOnTaskLaunch="true" or "false"

但是当我使用我的应用程序打开 SVG 时,它们都没有使 onNewIntent 函数被调用。相反,它会显示之前的状态(按预期调用 onPause 和 onResume,而改为调用 onCreate)。

我发现的唯一解决方法是使用 onPause() 方法调用 finish() 函数,以便它有效地终止应用程序。我不明白发生了什么,因为在我改变目标之前它在去年就起作用了。

每次访问调用意图所需的配置是什么?

没有答案的相关问题:

  • This blog 解释说我应该使用“singleTop”,但它不适用于我的情况。
  • This SO question 没有任何答案。
  • This famous SO question 描述了意图的设置。但就我而言,我自己不会创建意图,android 会。

【问题讨论】:

  • 你有没有找到解决办法?
  • 是的,看看我的回答,谢谢你的提问。

标签: android onnewintent


【解决方案1】:

目前,我的程序运行良好,可以根据需要加载 SVG。关于我的配置的一些要点(也许它可以帮助)

  • 我的目标是 Android API 15。我放弃了 19。
  • 我在AndroidManifest.xml 中使用android:finishOnTaskLaunch="true"
  • 我不在onPause()方法中调用finish()
  • OnNewIntent 永远不会被调用,但会调用 onCreate 方法来解析新的意图。
  • 活动清单的内容如下:

    <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>
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-23
    • 1970-01-01
    • 1970-01-01
    • 2014-08-08
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多