android


Intent is losing values in extras


I have a GCMIntentService where I am setting details for the intent and all when the user clicks on the notification. My code snippet relevant to this is below:
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, CustomTabActivity.class);
if (noteId != null && value != null) {
notificationIntent.putExtra("noteId", noteId);
notificationIntent.putExtra("value", value);
}
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification updateComplete = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(msg)
.setTicker(title)
.setWhen(System.currentTimeMillis())
.setContentIntent(contentIntent)
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true)
.setSmallIcon(R.drawable.icon)
.build();
notificationManager.notify(100, updateComplete);
Whenever CustomTabActivity.class is opened, the getExtras() call is always null. Why is it that I am not able to get the values from intent?
I read the following for this and was not able to solve it:
how to pass string one activity to another?
Android - how can I send a GCM push notification with instructions of which activity to load?
I found the bulk of the problem here. Turns out that since I had singleTop for the activity, the intent from getIntent() was the old one. This code works:
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent.getExtras() != null) {
String noteId = intent.getExtras().getString("noteId");
String value = intent.getExtras().getString("value");
}
}
onNewIntent gets called when the user clicks the notification.
Try This :
private static int count = 1;
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(mContext, (int)(Math.random() * 100), new Intent(),PendingIntent.FLAG_UPDATE_CURRENT);
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, gcmData.getString("message"), when);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.setLatestEventInfo(mContext, gcmData.getString("type"), intent.getExtras().getString("message"), contentIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(count, notification);
count = count + 1;

Related Links

OnItemClickListener() is not working in api 16
Genymotion devices are not visible after changing adb sdk path
Pocketsphinx decoder fails to initialize
display google forms in webview using android studio
How to make onPreExecute()?
In app subscription minimum rate
Center align selected item in new master detail activity
Qr and bar code scanner doesn't support portrait mode
Null value replace android [closed]
Xamarin android compiled app is empty
java.lang.ClassCastException: android.support.v7.widget.RecyclerView cannot be cast to android.support.v4.widget.SwipeRefreshLayout
How to import a library from github?
How to download a Gif from internet and save it into the app directory - android
one signal script androidmanifest xml Unable to start activity
Expandable ListView does not expanding
Why do I have to re-encode to utf-8 my encoded JSON response in order to save it to SQLite?

Categories

HOME
httparty
prism
ggplot2
dns
ecmascript-6
pagination
jax-rs
jmx
nuget
visual-studio-emulator
python-multithreading
missing-data
lanczos
mql5
categorical-data
dkim
alamofire
renjin
linear-algebra
alpacajs
null-pointer
dimensional-modeling
google-content-api
sigma.js
cgbitmapcontext
href
gulp-watch
r-mice
comparator
beta
google-api-client
android-things
cppreference
eviews
testbed
catch-unit-test
laravel-eloquent
sharding
installscript
jwplayer6
raft
lint
smoothstate.js
tcc
angular-http
flask-login
spring-integration-sftp
mschart
rserve
colorbar
gpg-signature
baidu
rmongo
signalr.client
expectations
firebase-security
lua-telegram-bot
angular-ui-typeahead
thread-sleep
user-management
xenomai
botan
nsurlsessiondatatask
entity-framework-4.3
code-documentation
variadic-templates
webfinger
wcm
memset
gwt-openlayers
hibernate-entitymanager
modular
mvc-editor-templates
wp7test
bjyauthorize
intersect
android-loadermanager
uimanageddocument
extconf.rb
objectquery
apache-commons-dbutils
winmain
entitydatasource
mbeans
updatesourcetrigger
openfaces
scrollbars
sifr
cldc
change-management
mathematical-typesetting
great-circle
idatareader

Resources

Encrypt Message