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