Search code examples
androidserviceandroid-intentundefinedonstart

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


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;
}

Solution

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

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