0

我正在尝试创建一次性设备(信息亭应用程序)并按照以下教程进行操作: https ://codelabs.developers.google.com/codelabs/cosu/index.html?index=..%2F..%2Findex #0

该代码工作正常,除了“重启”的情况。每次重新启动后,它都无法锁定应用程序,每次重新启动后都会陷入“LOCK_TASK_EXITING”。

07-05 15:45:14.583   785   802 V ActivityManager: Broadcast: Intent { act=android.app.action.LOCK_TASK_ENTERING flg=0x10 cmp=com.google.codelabs.cosu/.DeviceAdminReceiver (has extras) } ordered=false userid=0 callerApp=ProcessRecord{6438256 785:system/1000}
07-05 15:45:14.584   785   802 V ActivityManager: Broadcast: Intent { act=android.app.action.LOCK_TASK_EXITING flg=0x10 cmp=com.google.codelabs.cosu/.DeviceAdminReceiver } ordered=false userid=0 callerApp=ProcessRecord{6438256 785:system/1000}
4

1 回答 1

0

GitHub ...一个人可以解决这个问题:

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if (mSharedPreferences.getBoolean(KEY_PREF_RECREATED, false)) {

        mSharedPreferences.edit().putBoolean(KEY_PREF_RECREATED, false).apply();

        // start LOCK TASK here

    } else {

        mSharedPreferences.edit().putBoolean(KEY_PREF_RECREATED, true).apply();

        finish(); // close the app
        startActivity(new Intent(this, MainActivity.class)); // reopen the app
    }

    setContentView(R.layout.activity_main);
}
于 2018-07-13T05:17:42.333 回答