Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making activity runs in background

I m new in android, I'm not much aware about services.i have an activity class with a UI, i want to make this activity class runs in background, when i click the back button. how to make my activity runs in background like a service, plz help me..

like image 315
Jesbin MJ Avatar asked Mar 25 '13 17:03

Jesbin MJ


1 Answers

You cannot really run an Activity on background! When an activity is not on foreground it gets to onStop and then the system could terminate it, to release resources, by onDestroy method! see Activity Lifecycle

In order to run on background you need to create a Service or IntentService

Checkout android javadoc about Services here and here or IntentService

and here is a third-party Android Service Tutorial

Edit: you may also need a communication between your service and your activity so you can get through that: Example: Communication between Activity and Service using Messaging

like image 111
madlymad Avatar answered Oct 25 '22 13:10

madlymad