What is the difference between the Windows Phone fallback event and the Android fallback event

Source: Internet
Author: User
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);
        }
    }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.