How can I send data from the current Activity to the background Service class that is running at a specific time? I tried setting in Intent.putExtras() but I don't get it in the Service class
The code in the Activity class that calls Service .
Intent mServiceIntent = new Intent(this, SchedulerEventService.class); mServiceIntent.putExtra("test", "Daily"); startService(mServiceIntent);
Code in the Service class. Put in onBind() and onStartCommand() . None of these methods print a value.
@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; }
source share