如何防止信息亭应用重新启动后启动两次

问题描述

我已成功使用以下策略使用Android管理API创建了信息亭应用程序:

{
  "appAutoUpdatePolicy" : "ALWAYS","applications" : [ {
    "defaultPermissionPolicy" : "GRANT","installType" : "KIOSK","managedConfiguration" : {
      "deviceId" : "36edd69cd4c25e4c"
    },"packageName" : "com.example.app"
  } ],"blockApplicationsEnabled" : true,"bluetoothDisabled" : true,"dataRoamingDisabled" : true,"debuggingFeaturesAllowed" : true,"factoryResetDisabled" : true,"installAppsDisabled" : true,"keyguardDisabled" : true,"name" : "enterprises/LC0xxxxxxx/policies/policy_locked36edd69cd4c25e4c","playStoreMode" : "WHITELIST","safeBootDisabled" : true,"screenCaptureDisabled" : true,"systemUpdate" : {
    "endMinutes" : 240,"startMinutes" : 120,"type" : "WINDOWED"
  },"uninstallAppsDisabled" : true,"version" : "3"
}

重新启动后,我的应用程序自动启动,阻止访问默认主屏幕。但是,在第一次启动后约有15秒,另一个启动了,因此已经处于RESUMED状态的应用程序将再次启动,因此旧活动及其包含的所有片段都将被销毁并替换为新实例。我已经尽力确定是什么原因导致了两次单独的发射,但是我得到的唯一线索是这两个日志以15-20秒的间隔依次出现:

2020-08-25 13:34:44.111 1074-2694/? I/ActivityManager: START u0 {act=android.intent.action.MAIN typ=null flg=0x10000000 cmp=ComponentInfo{com.example.app/com.example.app.presentation.ui.activities.MainActivity}} from uid 10132

2020-08-25 13:35:00.525 1074-2694/? I/ActivityManager: START u0 {act=null typ=null flg=0x10008000 cmp=ComponentInfo{com.example.app/com.example.app.presentation.ui.activities.MainActivity}} from uid 10136

我找到了解决此问题的方法:我添加了BroadcastReceiver,它接收ACTION_BOOT_COMPLETED事件并在SharedPreferences中写入布尔值标志。因此,在MainActivity中,我检查此标志,如果它为假,则显示Splash屏幕而不是主ui。这是因为在这两次启动之间就收到了ACTION_BOOT_COMPLETED。 但是我的问题是-如果没有这种“肮脏”的解决方法,是否有什么好的方法可以解决此问题?我很确定两次启动信息亭应用程序不是预期的行为,但我不知道自己做错了什么。

如果这很重要,这也是我的AndroidManifest.xml的一部分:

        <activity
        android:theme="@style/AppTheme.Launcher"
        android:name=".presentation.ui.activities.MainActivity"
        android:launchMode="singleTask"
        android:lockTaskMode="if_whitelisted"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>

            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <action android:name="android.intent.action.DIAL" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="tel" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.DIAL" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...