I have the following code
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if(intent != null) {
Log.i("INTENT", intent.getAction().toString());
}
return START_STICKY;
}
but it always returns NullPointerExceptionin a string:
Log.i("INTENT", intent.getAction().toString());
Why? I check above if the intent variable is not zero. If this case executes the following code. But I still had a nullpointer exception.
The service starts from this activity:
startService(new Intent(this, MainService.class));
What am I doing wrong?
source
share