I am developing an application that can send location details to a web service in .net I am able to generate co-ordinates and send it to webservice. The problem is I want the user to enter username when he starts the application for the first time and store in SharedPreference (I am able to do that) But after that I want the application to work as a service as it doesnt have any GUI. Please help me with this.
Asked
Active
Viewed 128 times
1
-
I think you shud check shared preference if it has the value then do not initiate activities with UI.Take some OS event to initiate service. – Shruti May 03 '13 at 12:52
1 Answers
2
You need two things:
A service which runs in the background and is started on boot. This will do the core work. A basic service tutorial is here: http://techblogon.com/simple-android-service-example-code-description-start-stop-service/ Once you've got that running, you will need to add your location sending code to it's startup routine, and then configure it to call it self on a regular basis (say using Alarm Manager). There are plenty of tutorials out there on doing this kind of thing.
An (standard) activity which accepts the user information. This will run when the user "runs" the application and should also start the service. You can configure this activity to have the user feel you wish.

Neil Townsend
- 6,024
- 5
- 35
- 52
-
1That's right. I'd only add that starting from a nice read of http://developer.android.com/reference/android/app/Service.html is always a good choice – sataniccrow May 03 '13 at 12:56
-
Thanks Neil, Right now I have written the procedure to send the location to web service in onClick listener of a button. Can you please tell me how do I integrate that code to service. ? It would be really great if you can help. – Jimmy Shah May 03 '13 at 13:10
-
-
Neil Sir, There is another doubt. I can successfully start my service and all things are happening. But I want to ask the question when the android reboots, I'll have to start my service once again. My service is activated through my activity class. Any idea how to do that ? – Jimmy Shah May 04 '13 at 13:07
-
See: http://stackoverflow.com/questions/4562734/android-starting-service-at-boot-time – Neil Townsend May 04 '13 at 14:39