Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I want to implement Mobile Back Button Functionality in my Xamarin Android Application.
Basically I had done following code in all the pages:-
C#
public override bool OnKeyDown(Keycode keyCode, KeyEvent e)
{
    if (e.KeyCode == Keycode.Back) {
    	base.OnBackPressed ();
    	// Transition your Fragments here
    } 

    return base.OnKeyDown(keyCode, e);
}

Now the issue which i am facing is, i had opened multiple pages in following sequence :-
Home Page -> Listing -> Detail -> Listing -> Detail etc.
Now on pressing back button , it traverse back to all of the pages in following order :-
Detail -> Listing -> Again Detail(should not to come) -> Listing(should not to come) -> Home -> Exit

What i need is Detail -> Listing -> Home -> Exit only.

I had tried with Finish() too but it doesn't work.
Can anyone help me out?

Thanks in Advance.
Posted
Updated 1-Feb-16 22:35pm
v2
Comments
Richard MacCutchan 2-Feb-16 4:36am    
The sequence you see is correct, it works backwards through each intent. If you wish to change the order, then you need to keep track of forward motion and skip the duplicates when moving backwards.
Member 4345489 2-Feb-16 4:42am    
Hi Richard,

Thank you so much for your reply.
Can you tell me how can i achieve that?
Do i need to code for that and maintain each forward and backward pages or is there any direct code for that?
Richard MacCutchan 2-Feb-16 5:49am    
I have no idea if there is any direct code for that, it is not anything I have ever tried.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900