0

I am new to android. I need a service(in a separate thread)which sends the sensed data from location sensor to the server at regular intervals. Can anybody please explain with an example. I mean just the part for service, how to implement it in a separate thread where to place the code to send data to server. I have already implemented the code for getting data from sensor.

Thanks in advance!

goldenptr
  • 321
  • 1
  • 4
  • 14

1 Answers1

0

You have to use the Service class by implementing it with startForeground

Read this article: http://android-developers.blogspot.de/2010/02/service-api-changes-starting-with.html

and read this thread: Implement startForeground method in Android

 final static int myID = 1234;

//The intent to launch when the user clicks the expanded notification
Intent intent = new Intent(this, SomeActivityToLaunch.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0);

//This constructor is deprecated. Use Notification.Builder instead
Notification notice = new Notification(R.drawable.icon_image, "Ticker text", System.currentTimeMillis());

//This method is deprecated. Use Notification.Builder instead.
notice.setLatestEventInfo(this, "Title text", "Content text", pendIntent);

notice.flags |= Notification.FLAG_NO_CLEAR;
startForeground(myID, notice);
Community
  • 1
  • 1
mapodev
  • 988
  • 8
  • 14