Android Development Note: The Replication onbackpressed () of the return key _android

Source: Internet
Author: User
In Android development, when the return key is pressed when the trigger condition is not met, it needs to be detected. In particular, the current activity requires a forward activity to deliver the message. That is, Activity1 jump to Activity3 if the use of startactivityforresult this way, if you do not rewrite the return key, the program does not know what to return to Activity1 what content will be an error. Therefore, you must rewrite the Activity3 's return key, and let him send an "ERROR" message here:
Copy Code code as follows:

@Override
    public void onbackpressed () {
 & nbsp;    //TODO auto-generated method stub
     Intent backintent = new Int ENT (Activity3.this, Activity1.class);
       Bundle Bundle = new Bundle ();
       if (!clickok)
            bundle.putstring ("Send", "ERROR");
       Backintent.putextras (bundle);
       Activity3.this.setResult (1, backintent);
       Activity3.this.finish ();
       //super.onbackpressed ();               
   }

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.