I have a widget. It has for 4 buttons. Each button should call the
same Widget and update some data in the widget. So,
I have 4 different action registered in the Manifest.xml.
I create 4 different PendingIntents, for each button 1.
However, when I click the buttons, only the button for which I
attached his PendingIntent first, is called. The other 3 buttons fail.
Here is my code:
Intent nextSaintIntent = new Intent(context,
SaintWidgetProvider4x2.class);
nextSaintIntent.setAction("com.radlmaier.saintscalendarwidget.ACTION_NEXT_SAINT");
nextSaintIntent.putExtra("action", "next_saint");
nextSaintIntent.putExtra("id", saintId);
nextSaintIntent.putExtra("widget_id", widgetId);
PendingIntent nextSaintPendingIntent =
PendingIntent.getBroadcast(context, widgetId,
nextSaintIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.image_button_next_saint,
nextSaintPendingIntent);
Intent nextSaintOfDayIntent = new Intent(context,
SaintWidgetProvider4x2.class);
nextSaintIntent.setAction("com.radlmaier.saintscalendarwidget.ACTION_NEXT_SAINT_OF_DAY");
nextSaintOfDayIntent.putExtra("action", "next_saint_of_day");
nextSaintOfDayIntent.putExtra("id", saintId);
nextSaintOfDayIntent.putExtra("widget_id", widgetId);
PendingIntent nextSaintOfDayPendingIntent =
PendingIntent.getBroadcast(context, widgetId,
nextSaintOfDayIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.image_button_next_saint_of_day,
nextSaintOfDayPendingIntent);
Intent previousSaintIntent = new Intent(context,
SaintWidgetProvider4x2.class);
nextSaintIntent.setAction("com.radlmaier.saintscalendarwidget.ACTION_PREVIOUS_SAINT");
previousSaintIntent.putExtra("action", "previous_saint");
previousSaintIntent.putExtra("id", saintId);
previousSaintIntent.putExtra("widget_id", widgetId);
PendingIntent previousSaintPendingIntent =
PendingIntent.getBroadcast(context, widgetId,
previousSaintIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.image_button_previous_saint,
previousSaintPendingIntent);
Intent previousSaintOfDayIntent = new Intent(context,
SaintWidgetProvider4x2.class);
nextSaintIntent.setAction("com.radlmaier.saintscalendarwidget.ACTION_PREIOUS_SAINT_OF_DAY");
previousSaintOfDayIntent.putExtra("action",
"previous_saint_of_day");
previousSaintOfDayIntent.putExtra("id", saintId);
previousSaintOfDayIntent.putExtra("widget_id", widgetId);
PendingIntent previousSaintOfDayPendingIntent =
PendingIntent.getBroadcast(context, widgetId,
previousSaintOfDayIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.image_button_previous_saint_of_day_,
previousSaintOfDayPendingIntent);
Here is my Manifest:
<receiver
android:name="com.radlmaier.saintscalendarwidget.SaintWidgetProvider4x2"
android:label="@string/name_widget4x2">
<intent-filter>
<action
android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:resource="@xml/widget4x2_info"
android:name="android.appwidget.provider"/>
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
<intent-filter>
<action
android:name="android.intent.action.DATE_CHANGED"/>
</intent-filter>
<intent-filter>
<action
android:name="com.radlmaier.saintscalendarwidget.ACTION_NEXT_SAINT"/>
</intent-filter>
<intent-filter>
<action
android:name="com.radlmaier.saintscalendarwidget.ACTION_PREVIOUS_SAINT"/
>
</intent-filter>
<intent-filter
android:label="com.radlmaier.saintscalendarwidget.ACTION_NEXT_SAINT_OF_DAY"></
intent-filter>
<intent-filter>
<action
android:name="com.radlmaier.saintscalendarwidget.ACTION_PREVIOUS_SAINT_OF_DAY"/
>
</intent-filter>
</receiver>
And thats the LogCat:
04-10 02:48:33.476: D/SaintWidgetProvider4x2(11593):
intent.toString(): Intent { flg=0x10000000
cmp=com.radlmaier.saintscalendarwidget/.SaintWidgetProvider4x2
bnds=[168,209][240,281] (has extras) }
04-10 02:48:33.476: D/SaintWidgetProvider4x2(11593): is not null: true
04-10 02:48:33.484: D/AndroidRuntime(11593): Shutting down VM
04-10 02:48:33.484: W/dalvikvm(11593): threadid=1: thread exiting with
uncaught exception (group=0x40015578)
04-10 02:48:33.496: E/AndroidRuntime(11593): FATAL EXCEPTION: main
04-10 02:48:33.496: E/AndroidRuntime(11593):
java.lang.RuntimeException: Unable to start receiver
com.radlmaier.saintscalendarwidget.SaintWidgetProvider4x2:
java.lang.NullPointerException
04-10 02:48:33.496: E/AndroidRuntime(11593): at
android.app.ActivityThread.handleReceiver(ActivityThread.java:1809)
04-10 02:48:33.496: E/AndroidRuntime(11593): at
android.app.ActivityThread.access$2400(ActivityThread.java:117)
04-10 02:48:33.496: E/AndroidRuntime(11593): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
04-10 02:48:33.496: E/AndroidRuntime(11593): at
android.os.Handler.dispatchMessage(Handler.java:99)
04-10 02:48:33.496: E/AndroidRuntime(11593): at
android.os.Looper.loop(Looper.java:130)
04-10 02:48:33.496: E/AndroidRuntime(11593): at
android.app.ActivityThread.main(ActivityThread.java:3687)
04-10 02:48:33.496: E/AndroidRuntime(11593): at
java.lang.reflect.Method.invokeNative(Native Method)
04-10 02:48:33.496: E/AndroidRuntime(11593): at
java.lang.reflect.Method.invoke(Method.java:507)
04-10 02:48:33.496: E/AndroidRuntime(11593): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:842)
04-10 02:48:33.496: E/AndroidRuntime(11593): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
04-10 02:48:33.496: E/AndroidRuntime(11593): at
dalvik.system.NativeStart.main(Native Method)
04-10 02:48:33.496: E/AndroidRuntime(11593): Caused by:
java.lang.NullPointerException
04-10 02:48:33.496: E/AndroidRuntime(11593): at
com.radlmaier.saintscalendarwidget.SaintWidgetProvider4x2.onReceive(SaintWidgetProvider4x2.java:
117)
04-10 02:48:33.496: E/AndroidRuntime(11593): at
android.app.ActivityThread.handleReceiver(ActivityThread.java:1798)
04-10 02:48:33.496: E/AndroidRuntime(11593): ... 10 more
As you can see, the first buttons clicked is processed nicely,
the other buttons cause a NullPointerException, because the received
Broascast seems to be null?
The NullPointerException is thrown in that line in the onReceive()
metod:
if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
{
.... do something
}
so seems the intent,getAction is null?
Why does this happen?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en