A bit of theory:
Intent - an abstract description of the operation being performed.
Intent often described online as an intention to perform an operation. And this description is quite successful due to the fact that the Intent MB is explicit and implicit.
Basic use:
In startActivity to start an Activity.
In broadcastIntent to send it to any interested components BroadcastReceiver.
- In startService (Intent) or in bindService (Intent, ServiceConnection, int) to communicate with the background service.
The most significant use is the beginning of an activity where it can be viewed as a link between actions. This is basically a passive data structure containing an abstract description of the action to be performed.
Bottom line: Intent is an entity that allows you to link application components, has the ability to manage them and can transfer data between components, which is what happens in your example.
Answer:
We start:
Intent intent = new Intent(this, CheatActivity.class); intent.putExtra(EXTRA_ANSWER_IS_TRUE, mAnswerIsTrue); startActivity(intent);
The intention to run from the current class -> CheatActivity.
Put intent (Bundle) on the key EXTRA_ANSWER_IS_TRUE (String) value mAnswerIsTrue (boolean).
We get:
mAnswerIsTrue = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE, false);
We are trying to get the variable mAnswerIsTrue (bool).
To do this, we get an intent with the getIntent command, we get a variable from the intent (Bundle) with the getBooleanExtra variable, if the key EXTRA_ANSWER_IS_TRUE does not exist, then we set the default value to it false .