This is the intent that is fired when a search suggestion for creating a contact is clicked on. Any extras from the Contacts.Intents.Insert class will be passed along to the create activity if there are no contacts to show. Passing true for the EXTRAFORCECREATE extra will skip prompting the user when the contact doesn't exist.
I might have misunderstood how intents are supposed to be used, so I might be asking the wrong thing here. If that's the case, please help me get on the right track with this anyway...
I've just started working on an android app that will poll my server for messages every so often, and when a new message is available, I want to show it to the user. I'm trying to implement this by having a
Service
that polls the server, and when a new message is received the service should give the message to an Activity
that shows it.To facilitate this communication, I'm trying to create an
Intent
with ACTION_VIEW
, but I can't figure out how to give the message to the activity. Is there no way to pass a string or a regular Java object via the intent?For what it's worth, this is what I'd like to do:
but of course, that doesn't even compile.
![Extras Extras](https://d2sm1axt7ic674.cloudfront.net/uploads/entity_screenshots/118505_1556690489.png)
Tomas AschanTomas Aschan
3 Answers
Use the Intent bundle to add extra information, like so:
And on the receiving side:
Or, to get all the extras as a bundle, independently of the type:
There are various signatures for the
putExtra()
method and various methods to get the data depending on its type. You can see more here: Intent, putExtra.EDIT: To pass on an object it must implement Parcelable or Serializable, so you can use one of the following signatures:
Telmo MarquesTelmo Marques
You can do the following to add information into the intent bundle:
Then in the activity you can retrieve like this:
NickNick
Starting the activity from your service each time a new message is received might not be what you want. For instance, if you are viewing a different activity you will be interrupted by the new message.
You can use sendBroadcast(intent) along with a BroadcastReceiver to notify an activity that a new message has been received.
benkdevbenkdev
Not the answer you're looking for? Browse other questions tagged androidandroid-intent or ask your own question.
In my Andoird application, i pass extras to other intent by below code :
in noteDetail, get extras by this code :
Application work correctly and extras pass and receive correctly until press back button on mobile phone and back to previous activity. again when i press the noteDetail button and go to noteDetail activity the previous note_id has remained and not clear.i want to clear extras when user press back button on mobile phone.
HajitsuHajitsu
1 Answer
Mohamed_AbdAllahMohamed_AbdAllah