微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我已成功使用以下策略使用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 举报,一经查实,本站将立刻删除。