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

查看:182
本文介绍了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天全站免登陆