tags:

views:

70

answers:

2

Hi,

I'm trying to launch a service from another service with certain extras. However, I can't retrieve those extras in the launched service, .getIntExtra returns a NullPointerException.

This is how I launch the service:

Intent serviceIntent = new Intent(context, RefreshService.class);
serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

PendingIntent contentIntent = PendingIntent.getService(this, 0, serviceIntent, 0);
updateViews.setOnClickPendingIntent(R.id.btnRefresh, contentIntent);


And this how I'm trying to receive the extras in the started service:

@Override    
public void onStart(Intent intent, int startId){
    super.onStart(intent, startId);
    mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
}

In my example, mAppWidgetId always resorts to the default value -1.

What am I doing wrong?


Thanks for your help,

Nick

A: 

Sounds suspiciously like this: http://stackoverflow.com/questions/3140072/android-keeps-caching-my-intents-extras-how-to-declare-a-pending-intent-that-kee

EboMike
Thanks for your answer, but in my case, no extra at all is (seemingly) passed to the started service, it's not a question of which is the most recent one. I tried adding the FLAG_UPDATE_CURRENT though, but that doesn't help :-/
Nick
ACtually, wait, those are two conflicting statements - at first, you say getIntExtra throws a NPE (indicating that intent is null), but then you say that it returns -1 (indicating that either the extra doesn't exist, or you actually pass in -1 - did you verify that you pass in the right value?).
EboMike
If you look at line four of the second code-block: getIntExtra resolves to "-1", as this has been specific as the default value (in case that the intent extra doesn't exist). If I would query the extra without specifying a default value, I would get a NPE.
Nick
A: 

I "solved" it by transmitting my custom values through .setAction and .setFlags instead of .putExtras, which works fine. I can retrieve these with .getAction and .getFlags

Nick