getIntent() method is undefined inside of onStartCommand() method of android service

Kevik picture Kevik · Oct 16, 2012 · Viewed 7.6k times · Source

Does anyone know why my getIntent() method is undefined for the android service and inside of the onStartCommand() method?

   @Override
public int onStartCommand(Intent intent, int flags, int startId){
super.onStartCommand(intent, startId, startId);

Intent i = getIntent();
Bundle extras = i.getExtras();
filename = extras.getString("filename");


 return START_STICKY;
}

Answer

Vincent Mimoun-Prat picture Vincent Mimoun-Prat · Oct 16, 2012

Because the intent is passed as a parameter of the function...

onStartCommand(Intent intent, ...
    Bundle extras = intent.getExtras();