Start your service like this;
Intent ir=new Intent(this, Service.class);
ir.putExtra("data", data);
this.startService(ir);
You attach your data as an intent extra.
Then to retrieve the data from the service;
data=(String) intent.getExtras().get("data");
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
protected void onStartCommand (Intent intent, int flags, int startId) {
data=(String) intent.getExtras().get("data");
}
public int onStartCommand (Intent intent, int flags, int startId)
IntentService
protected void onHandleIntent(Intent intent) {
data=(String) intent.getExtras().get("data");
}
protected abstract void onHandleIntent (Intent intent)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…