【问题标题】:simulate Home button behavior inside an activity模拟活动中的主页按钮行为
【发布时间】:2014-02-12 11:02:45
【问题描述】:

我想模拟软 Home 按钮的行为。我希望当用户在我的应用程序的特定活动中点击后退按钮时,这会进入后台并显示设备主页。我该怎么办(我知道我应该在活动中覆盖 onBackPressed())

【问题讨论】:

  • 类似问题asked here
  • 不相似,在这种情况下用户需要返回父活动。我需要模拟主页按钮的压力,并且不显示父活动:)

标签: android background android-activity


【解决方案1】:

如果您知道如何覆盖onBackPressed(),那么请覆盖此方法并在此方法中执行以下操作:

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

【讨论】:

    【解决方案2】:
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        Intent l = new Intent(Friend_list.this, HomeActivity.class);
        startActivity(l);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多