如何将数据从当前
Activity
发送到在特定时间运行的后台Service
类?我尝试将其设置为Intent.putExtras()
,但我在Service
类中没有得到它。
Activity
类中调用Service
的代码。Intent mServiceIntent = new Intent(this, SchedulerEventService.class);
mServiceIntent.putExtra("test", "Daily");
startService(mServiceIntent);
Service
类中的代码。我试图将其放在onBind()
和onStartCommand()
中。但是这两个方法都未打印出值。
@Override
public IBinder onBind(Intent intent) {
//Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
//String data = intent.getDataString();
Toast.makeText(this, "Starting..", Toast.LENGTH_SHORT).show();
Log.d(APP_TAG,intent.getExtras().getString("test"));
return null;
}