My code is as follows:
First, I was wondering about line 20:
I had two questions:
a. Why is MY_MESSAGE assigned to com.example.myfirstapp.MESSAGE?
b. What is com.example.myfirstapp.MESSAGE?
c. I mever made MESSAGE anywhere; is this automatically made like the variables in r.java file, or do i need to make it somewhere?
Secondly, about line 40: intent.putExtra(EXTRA_MESSAGE, message);
I am not sure if this method adds a message to the upcoming activity to be called or what… Partly, I am struggling to understand this due to not knowing the point of an Intent fully.
I want to read my 200 fundamental section on what everything is, but I have set deadlines and I have been told not to take that approach for the time being for this project
With given the explanation of the Android Docs , I know an intent is:
The Intent itself, an Intent object, is a passive data structure holding an abstract description of an operation to be performed
A.) Could someone explain what the intent is used for or give some better quick articles than just the docs?
B.) Explain what putExtra( ) does and and these parameters more clearly:
- name The name of the extra data, with package prefix.
- value The String array data value
An
Intentis appropriately named; it’s what you want to be done. As the documentation says:By your code, you are familiar with starting an
ActivityviaIntent:This uses your current
Activityas the context from which to start theIntent, and gives the target class to launch. You already know this, I think. Basically, theIntentis just a guide for the Android device to follow so that it launches the right target with the right information.Onto your real questions:
putExtra, you are providing theIntentwith data it can give to the “to” part of the code.nameparameter is best summed up by the documentation: “The name of the extra data, with package prefix.” This is like a key in aHashMap; it is a string identifier of the content you are packaging. They tell you to use your package’s prefix, just to prevent confusion. In your case, you should be using “com.SG.Three_Piece_Radio.YOURKEYNAME”; this does not have to be declared anywhere, nor is it a constant. Just a string. The value is just the contents of the extra (the data); this can be a ton of different things–short,int,String,Parcelable, and many more. (These can all be found in the variousputExtras in theIntentdocs.)Once your
Intentis received, you can use those same bits of data (for example,String myStr = getIntent().getStringExtra("com.SG.Three_Piece_Radio.YOURKEYNAME");) and do whatever you wish with them in theActivityyou called.