【问题标题】:How can I close activites that I have accessed before, and jump to the main activity?如何关闭之前访问过的活动,然后跳转到主要活动?
【发布时间】:2016-02-04 19:59:49
【问题描述】:

在我的 MainActivity 中,我有一些按钮可以打开其他活动,并且在这些按钮中,我有更多按钮可以打开更多活动……

问题是这样的:

假设我在活动的第三个子级别中,我添加了一个菜单按钮,允许我返回到 MainActivity。但是,当我单击它时,MainActivity 会打开,但它显然不会关闭其他的。我怎样才能做到这一点?

这是进行跳转的当前代码块:

case Resource.Id.home:

Intent intent = new Intent (this, typeof(MainActivity));
this.StartActivity(intent);

return true;

【问题讨论】:

    标签: c# android xamarin


    【解决方案1】:

    你应该这样做

    Intent intent = new Intent (this, typeof(MainActivity));
    intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask | ActivityFlags.NewTask);
    this.StartActivity(intent);
    

    【讨论】:

      【解决方案2】:

      你想把除 Main 之外的任何活动都保留在 backstack 中吗?

      如果没有,您可以打开每一个而不将它们添加到 backstack。请参阅此处的示例Android: open activity without save into the stack

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-26
      • 1970-01-01
      • 2010-12-02
      • 2019-05-14
      • 1970-01-01
      相关资源
      最近更新 更多