Android single activity background runs, and activity hides but does not call the Ondestory method

Source: Internet
Author: User

Recently due to the project needs, need to implement an activity hidden function, click the button again in the activity without repainting, toss for several days are not resolved, the last two lines of code to fix this problem, really verified the android open a classic word: no you won't, Only you don't know. If you know, it will be very fast to develop. No nonsense, directly on the code, verified, there is certainly no problem.
1, directly on the code, when you need to hide the activity, call the Movetasktoback function.
public boolean onKeyDown (int keycode, keyevent event) {log.i (TAG, "Key_stuta =" + event.getaction ()); if (keycode = = Keyevent.keycode_back && event.getrepeatcount () = = 0) {//right-click Processing
    Movetasktoback (TRUE); }
  return true;}
2, add the activity in the manifest file startup mode, the following code:
<activity android:name= ". Presentation. Sessionactivity "android:configchanges=" Orientation|keyboardhidden|keyboard "android:launchmode=" sin Gleinstance "Android:theme=" @android: Style/theme.black.notitlebar "android:windowsoftinputmode=" Adju Stresize "> </activity>

Android:launchmode= "SingleInstance" is the key to tell the system to start with a singleton mode, and if the activity is not ondestory, you do not need to create the activity again.


Android single activity background runs, and activity hides but does not call the Ondestory method

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.