简体   繁体   中英

How to hide my application but not close/finish it

I would like to let user to leave my application by hiding it but not finishing it.

I could call finish() in my main activity, but it takes some time to do that. It's not good for user experience, therefore a better choice might be to hide it. Just I don't know how to achieve it.

Thanks for all the answer.


I am not trying to do something in the background, because I already have a service.

In my application, user might press an button to close my main activity. However, it take a little time to do that. At least after 0.5 sec, then I'll see my application disappear on screen.

However, if I press home key. My application is disappear immediately, so it's the effect I need.

您可以尝试在后台移动您的活动

moveTaskToBack(true);

If you need your app to continue running in the background, spawn the background code in a Service.

http://developer.android.com/reference/android/app/Service.html

The best advice here is simply to start looking at all of the garbage collection the app has to do and make sure you only keep things (connections, etc) open for as long as absolutely necessary.

Point is to limit the amount of stuff the app has to do to finally shut down.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM