I am currently learning how to program in Android. I read that the keys for Extras (to be put in an intent) usually start with the word "EXTRA", for example:
public static final String EXTRA_USER_CHEATED = "some unique string";
And that keys to objects that are to be saved in the Bundle usually start with the word "KEY", for example:
public static final String KEY_USER_CHEATED = "some other unique string";
What if I have a variable that I need to pass to another activity as an Extra, but I also need to be able to save that same variable in the Bundle for an activity? Should I
It's the end of an era at Google: The company's Android mobile platform is dropping its long-running dessert-themed naming convention, switching instead to a simple numerical format. Beginning with the release of Android 1.5, the mobile popular platform Google acquired along with its creator Android Inc.
Using putExtra() and getExtras() in android Intents are asynchronous messages which allow Android components to request functionality from other components of the Android system. For example an Activity can send an Intents to the Android system which starts another Activity .
I can't be sure of the answer, but from my understanding, the EXTRA_MESSAGE OR the KEY is merely a key to some value. You can have 2 different keys which point to the same data, so to answer your question, maybe just have both (i.e. option 1).
This short code snippet might give you a clue... notice that String message is the value associated with the key which is EXTRA_MESSAGE (see documentation for the putExtra
method).
public static final String EXTRA_MESSAGE = "com.whatever.appName.MESSAGE";
public void sendMessage(View view){
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With