【问题标题】:Setting app as home launches another instance将应用设置为主启动另一个实例
【发布时间】:2020-05-20 18:58:30
【问题描述】:

我想将我的应用程序设置为启动器(家庭应用程序),但有些行为我无法正确处理。首先,我打开应用程序并返回主屏幕,使其保持在后台。然后,当我在设置主页应用程序中设置以进行挖掘时,它会创建新实例。此外,当我返回到默认启动器应用程序的设置时,似乎没有显示在正在运行的应用程序列表中。我不确定如何正确使用它,我尝试了不同的启动模式,但似乎没有帮助。

这是我的清单文件

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="xxx" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:keepScreenOn="true" android:label="@string/activity_name" android:launchMode="singleTop" android:name="jk.cordova.plugin.kiosk.KioskActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.HOME" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.darryncampbell.cordova.plugin.intent.ACTION" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <receiver android:name="jk.cordova.plugin.kiosk.MyPackageReplacedEventReceiver">
            <intent-filter>
                <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
            </intent-filter>
        </receiver>
        <provider android:authorities="${applicationId}.darryncampbell.cordova.plugin.intent.fileprovider" android:exported="false" android:grantUriPermissions="true" android:name="com.darryncampbell.cordova.plugin.intent.CordovaPluginIntentFileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
        </provider>
    </application>
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
    <uses-permission android:name="android.permission.REORDER_TASKS" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>

【问题讨论】:

  • 显示你的清单
  • @Blundell Manifest 发布有问题。我的应用基于 ionic / cordova,所以大部分是由使用的插件修改的。

标签: java android ionic-framework android-activity kiosk-mode


【解决方案1】:

您将 launchMode 设置为 singleTop。这意味着如果它位于堆栈的顶部,您将永远只有一个实例。

文档

还可以创建“singleTop”活动的新实例来处理新意图。但是,如果目标任务在其堆栈顶部已经有活动的现有实例,则该实例将接收新意图(在 onNewIntent() 调用中);未创建新实例。在其他情况下——例如,如果“singleTop”活动的现有实例在目标任务中,但不在堆栈的顶部,或者如果它在堆栈的顶部,但不在目标任务中 -将创建新实例并将其推送到堆栈上。

你正在尝试什么:

首先我打开应用程序并返回主屏幕,使其保持在后台。

我认为 Launcher 之间的最近更新不会像你期望的那样工作。

然后,当我在设置主页应用程序中进行设置时,它会创建新实例。

是的,因为这是启动器,它会启动一个新进程。

此外,当我返回到默认启动器的设置时,应用程序似乎没有显示在正在运行的应用程序列表中。

启动器活动不显示在最近的应用中。

【讨论】:

    猜你喜欢
    • 2015-06-09
    • 1970-01-01
    • 2014-10-31
    • 1970-01-01
    • 2020-01-07
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 2014-10-31
    相关资源
    最近更新 更多