Reputation: 3430
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.
Upvotes: 3
Views: 6994
Reputation: 88092
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.
Upvotes: 0
Reputation: 14581
You could try to move your activity in the background
moveTaskToBack(true);
Upvotes: 9
Reputation: 8538
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
Upvotes: 0