导航到主屏幕时,Android应用程序无法重新启动

时间:2017-06-29 20:10:19

标签: android android-launcher

我们有一个适用于旧版Android的启动器应用程序。我们有一台运行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");

   }

}

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

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();

}

没有骰子。同样的行为。

我错过了什么? OS 5.1中有什么东西可以覆盖我们的启动器吗?再次按下主页按钮可按预期启动应用程序。通过按后退按钮从设置页面导航到主页不会。

我们在其他设备和操作系统上的工作原理。我们对4.1和6.1没有任何问题。

我们也像这样覆盖了后退按钮:

@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);
  }

}

谢谢!

1 个答案:

答案 0 :(得分:0)

添加     机器人:stateNotNeeded ="真"     机器人:clearTaskOnLaunch ="假" 我的清单照顾它。