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