Reputation: 853
Bundle extras = intent.getExtras();
if (extras != null) {
Toast.makeText(context, "Message recieved", Toast.LENGTH_SHORT).show();
}
What is the value stored in extras.. :?
Upvotes: 1
Views: 548
Reputation: 17278
Extras is a Bundle, so it'll usually hold a collection of values. From your code fragment, it is impossible to tell what is in there. It depends on what the code that created the intent put into the bundle.
If you want to know all keys in a Bundle, use Bundle.keySet().
Regarding your remark, there is no true "beginning of a program" in an Android application. Your activity is marked in the manifest as the 'launcher' activity. If your activity is started from the Launcher, the Extras will be empty. However, no-one is stopping you (or other applications) from starting your activity manually, providing data in the extras.
There is no magic involved here. If you don't put anything into the Extras, nothing comes out.
Upvotes: 0
Reputation: 13855
The values stored in extras are the values you put into the extras.
To add an extra to an intent, do the following before you start it.
intent = new Intent(v.getContext(),TextActivity.class);
intent.putExtra("Title", "I am An extra");
startActivityForResult(intent, -1);
Then in your intent, to read it do:
String title = getIntent().getStringExtra("Title");
The code in your question is just posting a popup message if there is an extra found. Currently you do not add anything to extras.
Upvotes: 1