Xamarin Android 中的 OnBackPressed [英] OnBackPressed in Xamarin Android

查看:32
本文介绍了Xamarin Android 中的 OnBackPressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

public override void OnBackPressed ()
{
base.OnBackPressed ();
}

  • 如何获取我的应用之前的状态?
  • Xamarin 是否有诸如BackStackEntryCount,如何使用?

    • How can I get previous state of my app?
    • Does Xamarin have such as BackStackEntryCount, how can I use it?

      比如我点击MainMenu->Study->Categories->FirstCategory,如果我点击Back,我想要Categories.

      For example I click MainMenu->Study->Categories->FirstCategory, if I click Back, I want to have Categories.

      推荐答案

      如果 Categories 活动在活动堆栈中位于 Selected 类别之前并且没有被标记为没有历史记录 OnbackPressed 没有覆盖基类/超类将带你回到类别类并点击 OnResume 方法.

      If the Categories activity precedes the Selected category in the activity stack and is not flagged for no history OnbackPressed without override of the base/super class will take you back to the categories class and hit the OnResume method.

      如果您在 OnCreate 中加载了 Categories 活动并且在 OnResume 中没有做任何事情,那么 OnBackPressed 应该以您离开它的状态显示前一个活动.

      If you loaded your Categories activity in OnCreate and dont do anything in OnResume then OnBackPressed should show the previous activity in the state you left it.

      如果你想让它做其他事情,然后覆盖 OnBackPressed 并将类别标记为没有历史记录.

      If you want it to do something else then override on OnBackPressed and flag Categories as no history.

      覆盖 OnBackPressed

      public override void OnBackPressed()
      {
          //Do not call the base method
          //base.Onbackpressed
          //Do something else
          *something else code*
          //finish this activity unless you want to keep it for some reason
          finish();
      
      }
      

      无历史

      [Activity
           (
      
           NoHistory = true         
      
           )
       ]
      
       Public Class Categories : Activity
      

      这篇关于Xamarin Android 中的 OnBackPressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆