An intent allows you to start an activity in another app by describing a simple action you'd like to perform(such as "view a map" or "take a picture") in an Intent object. This type of intent is called an implicit intent because it does not specify the app component to start, but instead specifies an action and provides some data with which to perform the action.
When you call startActivity() or startActivityForResult() and pass it an implicit intent, the system resolves the intentto an app that can handle the intent and starts its corresponding Activity.If there's more than one app that can handle the intent, the system presents the user with a dialog to pick which app to use.
Data and Extras
Some actions need a URI for data, others need one or more extras to be set.
Extras are key value pairs, the key is a string, either a standard value or defined by the component that accepts the intent.
https://developer.android.com/reference/android/content/Intent#EXTRA_EMA

Use the putExtra() and getXxxxExtra() methods to write/read extras. Make sure you use the correct type for the extra.
Extras are actually store in a Bundle, you can get and set the Bundle.
Bundle extras = intent.getExtras();
intent.putExtras(extras);
Intent Example
send a text message
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Hello There");
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
}Getting Rusults
To get a result back use:
startActivityForResult(intent, requestCode)
and override onActivityRusult
@Override
protected void onActivityResult(int requestCode, int resultCode,
@Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i(TAG,"result:"+data.getData());
}startActivityForResult(intent, requestCode)
第一个参数intent,和普通的startActivity()里的intent一样,里面放要请求的Activity和可以需要放的数据。
第二个参数requestCode,是一个请求代码,整型,这个可以自己随便定义,但这个数要大于等于0
例如应用程序第一个界面需要用户进行选择,但是这种选择的列表数据很复杂,需要启动另一个Activity让用户选择。当用户在第二个Activity中选择完后程序返回第一个Activity,此时第一个Activity必须获取并显示用户在第二个Activity中选择的结果。
1.当前Activity(主)需要重写onActivityResult(int requestCode, int resultCode, Intent intent),当被启动的Activity返回时,这个方法会被触发。 (第一个参数代表请求码,第二个参数代表Activity返回的结果码,这个结果码由开发者自定义)
2.使用startActivityForResult(Intent intent, int requestCode)方法打开新的Activity
3.被启动的Activity(新)需要调用setResult()方法设置处理结果
示例代码段:android: startActivityForResult用法(启动其他Activity并返回结果)_义小攻的博客-CSDN博客
部分转载自:
Android中的startActivityForResult()的基本用法_vida26的博客-CSDN博客_android startactivityforresult
https://developer.android.com/reference/android/provider/AlarmClock#EXTRA_MINUTES