Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android应用程序在导航到主屏幕时不会重新启动_Android_Android Launcher - Fatal编程技术网

Android应用程序在导航到主屏幕时不会重新启动

Android应用程序在导航到主屏幕时不会重新启动,android,android-launcher,Android,Android Launcher,我们有一个启动器应用程序,可以在旧版本的Android上正常工作。我们有一个运行安卓5.1的设备,并且遇到了问题 当在应用程序中按下后退按钮时,我们允许用户进入设置页面。按home键重新启动应用程序。按下其他设备上的后退按钮也会重新启动应用程序 在新设备上,按下后退按钮可以导航到Android主页。它不会启动应用程序 我们正在覆盖后退按钮,如下所示: @override public void onBackPressed() { // Display the password promp

我们有一个启动器应用程序,可以在旧版本的Android上正常工作。我们有一个运行安卓5.1的设备,并且遇到了问题

当在应用程序中按下后退按钮时,我们允许用户进入设置页面。按home键重新启动应用程序。按下其他设备上的后退按钮也会重新启动应用程序

在新设备上,按下后退按钮可以导航到Android主页。它不会启动应用程序

我们正在覆盖后退按钮,如下所示:

@override
public void onBackPressed() {

   // Display the password prompt if required
   if (PreferencesManager.isPasswordPresent()) {
   LeaveApplicationPasswordDialogFragment dialog = LeaveApplicationPasswordDialogFragment.getInstance();
   dialog.show(getSupportFragmentManager(), "password");
}
else {
   // Prompt whether we are about to leave the app
   LeaveApplicationDialogFragment dialog = null;
   MyApplication application = (MyApplication ) 
   getApplication();
   if (application.isDefaultLauncher()) {
      dialog = LeaveApplicationDialogFragment.getInstance("Are you sure you want to leave ** to access the device's settings?");
   }
   else {
      dialog = LeaveApplicationDialogFragment.getInstance("Are you sure you want to leave ***");
   }  
   dialog.show(getFragmentManager(), "leaving");

   }

}
@Override
public boolean onKeyDown(int keyCode, KeyEvent KEvent) {

  int deviceid = KEvent.getDeviceId();

  //Making sure not processing same key again
  if (KEvent.getRepeatCount() != 0) {
     return true;
  }

  if (!SettingsOpened) {
     int keyaction = KEvent.getAction();

     // "Esc" key can not be stooped id diveceid is non zero because it can be back key of android
     if (KEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && deviceid != 0) {
        return super.onKeyDown(keyCode, KEvent);
     }

     if (keyaction == KeyEvent.ACTION_DOWN) {
        String key = KeyEvent.keyCodeToString(keyCode); //wont work in version 11 or less

        if (keyCode != KeyEvent.KEYCODE_ENVELOPE) {
           Matcher matcher = KEYCODE_PATTERN.matcher(key);
           if (matcher.matches() || ExternalKeyboard.keyMatches(KEvent)) {
              int keyunicode = KEvent.getUnicodeChar(KEvent.getMetaState());
              char character = (char) keyunicode;

              //toast.makeText(this, "onKeyDown" + _lastChar + repeatcount, toast.LENGTH_SHORT).show();

              _lastChar = character;
              _actionDown = true;
              ExternalKeyboard.KeyboardAddChar(character);
           }
        }
     }
     return true;
  }
  else {
      return super.onKeyDown(keyCode, KEvent);
  }

}
在对话框片段中,我们接受确认并按如下方式处理:

public void exitToSettings() {
   GUIAndroidTouchBaseActivity.this.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
   shutdownOperations();
   finish();

}
根据一些研究和其他线索,我使用了我们的退出方法,如下所示:

public void exitToSettings() {

   Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
   intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
   intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

   GUIAndroidTouchBaseActivity.this.startActivity(intent);
   shutdownOperations();
   finish();

}
没有骰子。同样的行为

我错过了什么?OS5.1中是否有什么东西覆盖了我们的启动器?再次按下home(主页)按钮将按预期启动应用程序。通过按“上一步”按钮从“设置”页面导航到主页时,不会出现这种情况

我们所拥有的在其他设备和操作系统上有效。我们对4.1和6.1没有异议

我们还覆盖了后退按钮,如下所示:

@override
public void onBackPressed() {

   // Display the password prompt if required
   if (PreferencesManager.isPasswordPresent()) {
   LeaveApplicationPasswordDialogFragment dialog = LeaveApplicationPasswordDialogFragment.getInstance();
   dialog.show(getSupportFragmentManager(), "password");
}
else {
   // Prompt whether we are about to leave the app
   LeaveApplicationDialogFragment dialog = null;
   MyApplication application = (MyApplication ) 
   getApplication();
   if (application.isDefaultLauncher()) {
      dialog = LeaveApplicationDialogFragment.getInstance("Are you sure you want to leave ** to access the device's settings?");
   }
   else {
      dialog = LeaveApplicationDialogFragment.getInstance("Are you sure you want to leave ***");
   }  
   dialog.show(getFragmentManager(), "leaving");

   }

}
@Override
public boolean onKeyDown(int keyCode, KeyEvent KEvent) {

  int deviceid = KEvent.getDeviceId();

  //Making sure not processing same key again
  if (KEvent.getRepeatCount() != 0) {
     return true;
  }

  if (!SettingsOpened) {
     int keyaction = KEvent.getAction();

     // "Esc" key can not be stooped id diveceid is non zero because it can be back key of android
     if (KEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && deviceid != 0) {
        return super.onKeyDown(keyCode, KEvent);
     }

     if (keyaction == KeyEvent.ACTION_DOWN) {
        String key = KeyEvent.keyCodeToString(keyCode); //wont work in version 11 or less

        if (keyCode != KeyEvent.KEYCODE_ENVELOPE) {
           Matcher matcher = KEYCODE_PATTERN.matcher(key);
           if (matcher.matches() || ExternalKeyboard.keyMatches(KEvent)) {
              int keyunicode = KEvent.getUnicodeChar(KEvent.getMetaState());
              char character = (char) keyunicode;

              //toast.makeText(this, "onKeyDown" + _lastChar + repeatcount, toast.LENGTH_SHORT).show();

              _lastChar = character;
              _actionDown = true;
              ExternalKeyboard.KeyboardAddChar(character);
           }
        }
     }
     return true;
  }
  else {
      return super.onKeyDown(keyCode, KEvent);
  }

}
谢谢

添加 android:stateNotNeeded=“true” android:clearTaskOnLaunch=“false”
我的清单已经处理好了。

也许可以尝试为KeyEvent.KEYCODE\u返回覆盖onKeyDown?我们已经做到了:我发现将android:clearTaskOnLaunch=“false”添加到Manifist会导致应用程序在导航回主页时启动。不幸的是,它似乎在黑屏上“挂”了不同的时间,有时甚至是无限期。