I am a research student who just started the android programming for 3 weeks and I am trying to write an App which extracts data from accelerometer from the phone and writing it on my phone. My problem is that I would like to run my App (taking data from accelerometer) all time when the phone is up and running. What I mean is that my App has to run all time when somebody is calling, facebooking and so on. Is that possible? I would like to get some references.
Share
So for long-tasks you can use
AsyncTaskorServices. If you want to execute some task and it have to run also when its not connected with anyActivity(for example Music player, RSS which still run also after release from memory by memory manager), you should decide to useServicesand also you can combineServiceswithAsyncTask.Servicesare strong tool but work with them is not trivial. You are able to execute only oneServicein time and only oneServicecan running, one instance, one copy. This all is not free so you have to be careful because when you implementServicetoo dirty, it may cause premature exhaustion of battery.There is more approaches how to start
Servicesbut you have to read some tutorial and guides.I recommend to check this: Services, ServicesDemo – Using Android Services, Android Service Tutorial, Local Service | Android Tutorial for Beginners
Also have look at AsyncTask, Android Threads, Handlers and AsyncTask – Tutorial