Android two-time backend and android two-time backend

Source: Internet
Author: User

Android two-time backend and android two-time backend

Reprinted please indicate the source: http://blog.csdn.net/javacattle/article/details/41964045

You only need to add it to the *. Java file.
Private int back = 0;
// ======================== Back two exits =========================== ==@ Override public boolean onCreateOptionsMenu (Menu menu) {// you must change the menu. add (0, 2, 2, "quit"); return super. onCreateOptionsMenu (menu );}
@ Override public boolean onOptionsItemSelected (MenuItem item) {switch (item. getItemId () {case 2: Myback (); break;} return super. onOptionsItemSelected (item );}
@ Override public boolean onKeyDown (int keyCode, KeyEvent event) {// two back exits if (keyCode = KeyEvent. KEYCODE_BACK) {back ++; switch (back) {case 1: Toast. makeText (MainActivity. this, "exit once again", Toast. LENGTH_SHORT ). show (); break; case 2: back = 0; // initialize the back value Myback (); break;} return true; // set it to false to invalidate the back, true indicates no expiration} else {return super. onKeyDown (keyCode, event );}}
Public void Myback () {// close the MainActivity program. this. finish (); android. OS. process. killProcess (android. OS. process. myPid (); // closes the process}

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.