-1

I dont know much about intent (or android) so.. Can someone please explain me what is it exactly? i have search on the internet, A LOT. Also what does each line of this code do?

Intent intent = new Intent (this, DisplayMessageActivity.class);
intent.putExtra("a", "b");

Thanks in advance

qera hile
  • 112
  • 3
  • 10

3 Answers3

1

I suggest reading Android Intents

You couldn't have search for very long, since this is very basic topic. I suggest you read more of Android's API guides.

Line 1 = Create message that describes what to do, in this case start "DisplayMessagActivity"
Line 2 = Add content to the message

PrivatMamtora
  • 2,072
  • 2
  • 19
  • 29
0

The best example to state the behavior of Intent is it behaves like a POSTMAN that delivers message to the stated address.

Whether it may be calling service ,BroadCastRecivers ,Activity they are used in number of occassion.

Intents are asynchronous messages which allow application components to request functionality from other Android components. Intents allow you to interact with components from the same applications as well as with components contributed by other applications. For example, an activity can start an external activity for taking a picture.

Intents are objects of the android.content.Intent type. Your code can send them to the Android system defining the components you are targeting. For example, via the startActivity() method you can define that the intent should be used to start an activity.

An intent can contain data via a Bundle. This data can be used by the receiving component.

Intents can be used to start Service, call Activty, call Sub Activity, transfer the data between Activity or retrieve the data from Activity

Akshay Mukadam
  • 2,388
  • 1
  • 27
  • 40
0

Intent intent = new Intent (this, DisplayMessageActivity.class);

For this line, its function is to create a navigation from the current activity/page to the displaymessageactivity page.

it is like from here to there.

For this intent.putExtra("a", "b"); the purpose of this is to put like a temp storage/variable to pass to the next page for retrieval. In this case, you put the value "b" in the variable "a". With this method, you can use the value on the other activity or page.

All the above are just storing of info, it is not executed yet. if you want to execute the intent do the following

startActivity(intent);
James Yeo
  • 116
  • 1
  • 3
  • 12