OnBackPressed in Xamarin Android

余生长醉 提交于 2019-11-28 07:35:18

问题


I have:

public override void OnBackPressed ()
{
base.OnBackPressed ();
}
  • How can I get previous state of my app?
  • Does Xamarin have such as BackStackEntryCount, how can I use it?

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


回答1:


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.

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.

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

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

}

NoHistory

[Activity
     (

     NoHistory = true         

     )
 ]

 Public Class Categories : Activity



回答2:


public override void OnBackPressed ()
{
 finish();
}//end onBackPressed()


来源:https://stackoverflow.com/questions/18936749/onbackpressed-in-xamarin-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!