- Forum posts: 2
Nov 28, 2016, 8:27:19 AM via Website
Nov 28, 2016 8:27:19 AM via Website
I've started a few tutorials on android with a background in php, C, pascal etc.
The first demo they did was to try and trigger a second activity from main activity and pass data between them.
They did this by declaring a variable
Public static final int sharedata="Initial value";
The way I understand it final is the same as a constant ie in C you call
define mydata value since you will never be able to change it.
Later in their tutorial they create an onclick handler for a button and they create an intent to start the second activity. What left me confused is that they say
Intent.putExtra(senddata,"print me on the second activity!");
Then on the second activity they get the data by saying
Intent.getExtra(mainActivity.senddata);
Surely what happened is that they created a variable , changed its value in the onClick event handler and the read that variable from the second activity. That seems contrary to what final actually means.
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.