public void onbackpressed () {
finish ();
}
If you want to do a page navigation function, as far as I am concerned, I think that Windows Phone development is more humane than Android, more fool to save the corresponding data to the back key.
No, Windows Phone navigation is a lot more stupid because there's a goback approach in the Microsoft API that allows you to go back to the corresponding back interface because he's moving to the latest entry in the return stack. If there are no entries in the back stack, this method throws an exception, and the CanGoForward is always checked before calling this method. This is due to a page felt to the corresponding page management, voluntary adherence to the advanced principle is also very good management. In Android, the activity itself has a stack object that manages the corresponding activity, and it can be backed up voluntarily. The idea is good, but the reality is brutal. You see, we Android programmers have to listen to the event in the OnKey event to determine if he presses the back button. Here the event is that the activity must be delivered to intercept this backward-pressed event. My point here is to ask a question, OnKeyDown event is a layer to achieve the back event. Android is better than. NET! Open source, look at the code.
To invoke the onkeydown event in the activity, what is his source code: This is the onkeydown event that we defined in the activity, and his source code is this:
if (keycode = = keyevent.keycode_back) {
if (Getapplicationinfo (). targetsdkversion
>= build.version_codes. Eclair) {
event.starttracking ();
} else {
onbackpressed ();
}
return true;
}
To determine if the target version is larger than this version, call the Event.starttracking () method, trace the Event.starttracking () method, and find that he is always in a period of time to invoke.
Otherwise, the Onbackpressed method is invoked. This method is another how to bird like. The source code is as follows:
public void onbackpressed () {
Finish ();
}
He called finish to end the current activity, and his source code is this bird-like:
public void Finish () {
if (mparent = null) {
int resultcode;
Intent Resultdata;
Synchronized (this) {
resultcode = Mresultcode;
Resultdata = Mresultdata;
}
if (CONFIG.LOGV) log.v (TAG, "finishing self:token=" + Mtoken);
try {
if (Activitymanagernative.getdefault ()
. Finishactivity (Mtoken, ResultCode, Resultdata)) {
Mfinished = true;
}
} catch (RemoteException e) {
//Empty
}}
else {
mparent.finishfromchild (this);
}
}