1 of 10

Explicit and Implicit intents. �Sending and receiving data, using intent-filter. �Transferring data through Bundle.

2 of 10

An Intent in Android is a message object used to start another Activity, Service, or BroadcastReceiver and to pass data between them.��

Intent intent = new Intent(LoginActivity.this, HomeActivity.class);

intent.putExtra("username", "Bobur");

startActivity(intent);

In HomeActivity :

String name = getIntent().getStringExtra("username");

Explicit Intent

Used when you want to open a specific Activity within your own app.

  • Example: From LoginActivity to HomeActivity.

3 of 10

Implicit Intent (Noaniq Intent)���

Example: Opening a browser with a link.

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setData(Uri.parse("https://google.com"));

startActivity(intent);

The system will display apps like Chrome, Firefox, etc.

  • Used when you don’t specify the exact component, but rather an action.
  • Android will show apps that can handle that action.

4 of 10

2. Intent-filter

<activity android:name=".WebActivity">

<intent-filter>

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="http" />

<data android:scheme="https" />

</intent-filter>

</activity>

  • Defined in Manifest.xml.
  • Specifies which Activity can handle which implicit intents.

Now, if an intent with ACTION_VIEW and a https://... URL is sent, your WebActivity will appear as a choice.

5 of 10

Another Example: SMS Sending with Intent-filter�Manifest

<activity android:name=".SendSmsActivity">

<intent-filter>

<!-- Amal turi -->

<action android:name="android.intent.action.SENDTO" />

<!-- Kategoriya -->

<category android:name="android.intent.category.DEFAULT" />

<!-- Faqat sms va smsto sxemalarini qabul qilamiz -->

<data android:scheme="smsto" />

<data android:scheme="sms" />

</intent-filter>

</activity>

// Intent orqali kelayotgan ma'lumotni olish

Intent intent = getIntent();

Uri data = intent.getData();

// masalan: smsto:+998901234567

TextView tv = findViewById(R.id.textView);

if (data != null) {

tv.setText("SMS yuboriladigan raqam: " + data.getSchemeSpecificPart());

}

6 of 10

How does it work?�If such an Intent is sent from another place (for example, from a browser or another app):

Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("smsto:+998901234567")); intent.putExtra("sms_body", "Salom! Qalaysan?");

startActivity(intent);

Android tizimi sizga SMS yuborish uchun tanlov beradi: standart Messages app yoki sizning SendSmsActivity.

7 of 10

3. Sending and Receiving Data (putExtra, getExtra)�Sending a simple key-value pair:�

// Yuborish

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);

intent.putExtra("age", 22);

startActivity(intent);

// Qabul qilish

int age = getIntent().getIntExtra("age", 0);

8 of 10

A Bundle is like a container (key–value storage) used to pass multiple pieces of data together between Activities, Fragments, or Services.

  • It works almost like a HashMap, but it is optimized for Android and supports primitive types, Strings, and Serializable/Parcelable objects.

// Sending

Bundle bundle = new Bundle();

bundle.putString("username", "Bobur");

bundle.putInt("score", 95);

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);

intent.putExtras(bundle);

startActivity(intent);

  • If you want to send multiple values at once.
  • If you want a structured package of data (instead of many putExtra() calls).
  • Used heavily in Fragments (setArguments(Bundle) / getArguments()).

9 of 10

// Receiving

Bundle bundle = getIntent().getExtras();

if (bundle != null) {

String user = bundle.getString("username");

int score = bundle.getInt("score");

}

Example: Choosing photo from Galery

Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, 1);

If user choose an image from Galaery, you’ be returned Uri.

10 of 10

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setDataAndType(Uri.parse("file:///sdcard/music.mp3"), "audio/*");

startActivity(intent);

Android requests you to choose which app to open mp3 file.