# Intents

&#x20;Each activity is started or activated with an [`Intent`](https://developer.android.com/reference/android/content/Intent.html), which is a message object that makes a request to the Android runtime to start an activity or other app component in your app or in some other app.

#### Intent types <a href="#intent-types" id="intent-types"></a>

![](https://111087263-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_Lt0fyRsHcS_4ZagFx%2F-L_LwxbRy1MO9nB2GqhA%2F-L_LyBxnVKy6rIY0LiWZ%2Factivity-start.png?alt=media\&token=6e6ace3c-16bd-41d8-b1e0-10cf44bbb37e)

* _Explicit intent:_ You use explicit intents to start components in your own app (for example, to move between screens in the UI).
* _Implicit intent:_ You do _not_ specify a specific activity or other component to receive the intent. Instead, you declare a general action to perform, and the Android system matches your request to an activity or other component that can handle the requested action.

#### Implicit intent

```
Intent intent = new Intent(CurrenActivity.this, TargetActivity.class);
startActivity(intent);
```

passing extra data to next activity

```
Intent intent = new Intent(CurrenActivity.this, TargetActivity.class);
intent.putExtra("key", "this is my message");
startActivity(intent);
```

Getting data on target activity&#x20;

```
String message = getIntent.getStringExtra("key");
```

**An example for implicit intent(take picture using camera)**

Implement on onCreateView method

```
Intent pictureIntent = new Intent(
        MediaStore.ACTION_IMAGE_CAPTURE
);
    startActivityForResult(pictureIntent,
            REQUEST_CAPTURE_IMAGE);
```

override onActivityResult method

```
 @Override
    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {
        if (requestCode == REQUEST_CAPTURE_IMAGE &&
                resultCode == RESULT_OK) {
            if (data != null && data.getExtras() != null) {
                imageView.setVisibility(View.VISIBLE);
                Toast.makeText(this, "got image", Toast.LENGTH_SHORT).show();
                Bitmap imageBitmap = (Bitmap) data.getExtras().get("data");
                imageView.setImageBitmap(imageBitmap);
            }
        }
    }
```
