将应用设置为主页会启动另一个实例

Setting app as home launches another instance

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

这是我的清单文件

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

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

文档

a new instance of a "singleTop" activity may also be created to handle a new intent. However, if the target task already has an existing instance of the activity at the top of its stack, that instance will receive the new intent (in an onNewIntent() call); a new instance is not created. In other circumstances — for example, if an existing instance of the "singleTop" activity is in the target task, but not at the top of the stack, or if it's at the top of a stack, but not in the target task — a new instance would be created and pushed on the stack.

你正在尝试什么:

First I open app and go back to main screen so it stays in background.

我不认为 Launcher 之间最近的工作方式与您期望的一样。

Then when I set in settings home application to mine it creates new instance.

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

Also when I go back in settings to default launcher app doesn't seem to show back in list of running applications.

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