Mobile Audio Finally, software Exit Function optimization

Source: Internet
Author: User

Now the software to the main page, click the Return key after the exit, if the user is not careful to point to, quit, less friendly, then you have to do a bit of interpretation here, when the user in 2 seconds and then click the Return button, then exit.

In mainactivity, rewrite the onkeydown () method.

Defines a Boolean isexit=false; Determine whether to exit the operation

The first time you receive a return key to listen, set Isexit to True, and then eject the toast, prompting the user to press and exit within 2 seconds.

Then a delay of 2 seconds to send a handler, in the handler will isexit=false; for 2 seconds did not press the return key, then you need to 2 times within 2 seconds to return the key to exit

The code is as follows:

boolean isexit; //whether exit/** *  implementation 2 seconds Press the return key, only exit function  *  @param  keycode * @ param event *  @return  */@Overridepublic  boolean onkeydown (Int keycode,  keyevent event)  {    if  (keycode==keyevent.keycode_back) {         if  (position!=0) {  //not home              position=0;             rg_bottom_tag.check (R.id.rb_video);             return  true;        }else  if   (!isexit) {            isexit=true;             toast.maketext (MainActivity.this, "Press and exit within 2 seconds" , Toast.length_short). Show (); &nbSp;           new handler (). postDelayed (new  Runnable ()  {                  @Override                  public void run ()  {                     isExit=false;                 }             },2000);            return  True;        }    }    return  super.onkeydown (keycode, event);}


As the video is only here, the project is here for the time being. If you can find the back of the video later, the app will be added after the function.



Remembering my first more formal Android project, though not fully functional, was more complete. The following days will summarize the project, and then continue to study hard.

As a person from Java to Android, I will continue to work hard to learn Android and accumulate technical strength.

Technology to change the fate!!!

August 1, 2017 0:01 minutes

Completed in Linhai Zhejiang province Linhai Prison Guest House.

This article is from the "Yuangushi" blog, make sure to keep this source http://cm0425.blog.51cto.com/10819451/1952532

Mobile Audio Finally, software Exit Function optimization

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.