I have an app that is set up to display an entry from a database as a notification when it receives a broadcast. The _id for that database entry is passed as an extra for the broadcast's intent. When the notification is clicked, the app is supposed to display that database entry in an activity.
So, here's a code sample from the Broadcast Receiver:
Long itemID = intent.getLongExtra("com.my.app.receiver.ID", -1);
MyDatabaseHelper helper = new MyDatabaseHelper(context);
Log.i("MyApp", "Received item "+itemID);
Intent pending = new Intent(context, NotifyDisplay.class);
pending.putExtra("com.my.app.NOTIFY", itemID);
PendingIntent onNotifyClick = PendingIntent.getActivity(context,
1234567, pending, PendingIntent.FLAG_ONE_SHOT);
From there, the PendingIntent is thrown into a notification, and the activity just uses getIntent().getLongExtra()
to grab that. However, LogCat shows a different story.
07-25 23:45:00.046: I/MyApp(19630): Received item 1
07-25 23:45:05.456: D/dalvikvm(19630): GC_EXPLICIT freed 47K, 52% free 3213K/6599K, external 6314K/7884K, paused 64ms
07-25 23:45:29.705: I/Notification(19630): Displaying task 0
07-25 23:45:29.755: D/AndroidRuntime(19630): Shutting down VM
07-25 23:45:29.755: W/dalvikvm(19630): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-25 23:45:29.847: E/AndroidRuntime(19630): FATAL EXCEPTION: main
Somehow, the app is now trying (and failing) to display the entirely wrong item. Can someone tell me why the extra is being changed as it's being passed?
I seemed to have solved the issue by using itemID.longValue()
as the extra I'm putting into pending
. Apparently, since getLongExtra()
grabs primitive values, putting in a Long
instead of a long
causes issues.