1

I would like to know if there is a way to automatically start an andriod service when application (without GUI) start ended. If there is a way to make this through the manifest? Or receive an ACTION via an intentReceiver?

Lucifer
  • 29,392
  • 25
  • 90
  • 143
Andro Ap
  • 71
  • 4

2 Answers2

1

don't set a layout for that activity. And start a service in that activity. check out for services. http://developer.android.com/reference/android/app/Service.html

AD14
  • 1,218
  • 19
  • 32
  • I created an ctivity that start my service, but this one is stopped when i call finish in my activity. Is ther a way to make sur the service will be running after the activity has been destroyed. PS : I call finish because the parent activity is waiting for a result (SetResult). – Andro Ap Dec 27 '11 at 11:10
  • OnCreate method of my activity : `@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); startService(new Intent( this , MyService.class)); setResult(RESULT_OK); finish(); }` – Andro Ap Dec 27 '11 at 13:28
  • when it starts a service, the service starts to run in the background. if you don't need to return to your activity you can remove the setResult. If you want to do something on finishing the service you can use a AysnTask. check AsyncTask. http://developer.android.com/reference/android/os/AsyncTask.html. And check this answer also http://stackoverflow.com/questions/4251623/android-service-stops-when-activity-is-closed – AD14 Dec 28 '11 at 04:21
0

A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use. Each service class must have a corresponding declaration in its package's AndroidManifest.xml. Services can be started with Context.startService() and Context.bindService().

Services....

Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133