I have to pass parameter from MyActivity.class to TestService.class. MyActivity is a Activity class and TestService is a Service that I have made for sending messages. I have to pass parameter from Activity to the Service, but when I call Intent i = getIntent();
in service class, I am getting an error getIntent() is undefined.
So, how can I send parameters from my Activity to Service?
Start your service like this;
You attach your data as an intent extra.
Then to retrieve the data from the service;
So you can access your parameter from either the onHandleIntent or onStartCommand Intent parameter. (depending on which type of service you are running) For Example;
Service
public int onStartCommand (Intent intent, int flags, int startId)
IntentService
protected abstract void onHandleIntent (Intent intent)
When you start Service with intent(having Data) then that intent is received in method
onStart(Intent intent, int startId)
orof your Service.So receive your data from this method having intent as parameter