Вопрос

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;
}
Это было полезно?

Решение

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

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

Другие советы

The getIntent() method is of Activity not of Service. In Activity if you want to get the current Intent then you can call the getIntent() method to get the intent. In service the onStartCommand() method has the parameter intent already so you can fetch the extra data passed with the intent.

You are already getting intent object from the onStartCommand() method. check it.

There's no getIntent() method in the Service class. You can use the intent argument as passed to onStartCommand

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top