What is an Intent in Android?

2019-01-03 07:08发布

  • What is an Intent in Android?
  • Can someone elaborate with an example?
  • What are the types of Intents, and why we are using them?
  • Why are Intents so important in Android?

16条回答
我命由我不由天
2楼-- · 2019-01-03 08:02

An Intent is a class,that is bind the information for doing some actions.

example:passing data one activity to another actvity when user perform such actions in

present activity.

查看更多
贼婆χ
3楼-- · 2019-01-03 08:03

You can think of an intent as an “intent to do something”. It’s a type of message that allows you to bind separate objects (such as activities) together at runtime.

If one activity wants to start a second activity, it does it by sending an intent to Android. Android will start the second activity and pass it the intent.

enter image description here

Head First Android Development

查看更多
别忘想泡老子
4楼-- · 2019-01-03 08:03

According to their documentation:

An Intent is an object that provides runtime binding between separate components (such as two activities). The Intent represents an app’s "intent to do something." You can use intents for a wide variety of tasks, but most often they’re used to start another activity.

Here is the link with example: http://developer.android.com/training/basics/firstapp/starting-activity.html#BuildIntent

As the document describes, in order to start an activity (you also need to understand what activity is) use the intent like below

/** Called when the user clicks the Send button */
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);
}
查看更多
手持菜刀,她持情操
5楼-- · 2019-01-03 08:03

In a broad view, we can define Intent as

When one Activity wants to start another activity it creates an Object called Intent that specifies which Activity it wants to start.

查看更多
beautiful°
6楼-- · 2019-01-03 08:04

Intents are used to initiate another activity from one activity.It is basically used for several purposes such as sending data to another activity from one activity,and for triggering purposes.

They are basically of two types

  1. Implicit intents.

  2. Explicit intents.

As a beginner I know this much,I think this will give some basic idea about android intents

查看更多
Luminary・发光体
7楼-- · 2019-01-03 08:05

Intent is an intention to perform an operation.

In detail you can refer

http://developer.android.com/reference/android/content/Intent.html

Also, in my blog

http://emergingandroidtech.blogspot.in/2014/11/what-is-intent-in-android.html

Take a look if it is helpful for you.

Thank you.

查看更多
登录 后发表回答