I am trying to send data from an activity to service via intents.
This is the code in my activity class
Intent i= new Intent(this,SampService.class);
i.putExtra("startTimeHour", timePicker1.getCurrentHour());
i.putExtra("endTimeHour", timePicker2.getCurrentHour());
i.putExtra("startTimeMinute",timePicker1.getCurrentMinute());
i.putExtra("endTimeMinute", timePicker2.getCurrentMinute());
startActivity(i);
This is the code in my service class
public class SampService extends Service implements Runnable {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
public void onCreate()
{
Toast.makeText(getApplicationContext(), "Service Created", Toast.LENGTH_LONG).show();
String startTimeHour,startTimeMinute,endTimeHour,endTimeMinute;
}
public void onStart()
{
Thread t=new Thread(this);
t.start();
}
public void run() {
}
SampleService is a Service, you should use
startService(i);instead ofstartActivity(i);The data attached to the intent can then be retrieved in the Service.