0% found this document useful (0 votes)
76 views4 pages

Layout Pertama: Nama: Rezky Rizqullah Kelas: XI PPLG 2 Materi: Intent

The document describes an Android application that demonstrates explicit and implicit intents. It includes the layout files for two activities, the Java code for the main and second activities, and the Android manifest. The main activity contains buttons that launch the second activity explicitly via an intent, and launch the browser implicitly by sending an intent to view a URL.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views4 pages

Layout Pertama: Nama: Rezky Rizqullah Kelas: XI PPLG 2 Materi: Intent

The document describes an Android application that demonstrates explicit and implicit intents. It includes the layout files for two activities, the Java code for the main and second activities, and the Android manifest. The main activity contains buttons that launch the second activity explicitly via an intent, and launch the browser implicitly by sending an intent to view a URL.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Nama : Rezky Rizqullah

Kelas : XI PPLG 2
Materi : Intent
Layout Pertama
Screenshot :

Layout Kedua
Screenshot :

Layout Implicit
Screenshot :

Source Code
activity_main :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">

<Button
android:id="@+id/explicitIntent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
android:text="Klik Disini untuk explicit intent"/>

<Button
android:id="@+id/implicitIntent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
android:text="Klik Disini untuk implicit intent"/>
</RelativeLayout>
activity_second :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">

<TextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Kalian berada di halaman kedua"
android:textAppearance="@style/TextAppearance.AppCompat.Display2"
/>

</RelativeLayout>
MainActivity.java
package com.example.belajar_intent;

import androidx.appcompat.app.AppCompatActivity;
import android.widget.Button;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity implements


View.OnClickListener {
Button explicitIntent;
Button implicitIntent;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

explicitIntent = (Button)findViewById(R.id.explicitIntent);
explicitIntent.setOnClickListener(this);

implicitIntent = (Button)findViewById(R.id.implicitIntent);
implicitIntent.setOnClickListener(this);
}
@Override
public void onClick(View v){
switch (v.getId()){
case R.id.explicitIntent:
Intent explicit = new Intent(MainActivity.this,
IntentActivity.class);
startActivity(explicit);
break;
case R.id.implicitIntent:
Intent implicit = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.w3schools.com/"));
startActivity(implicit);
break;
default:
break;
}
}
}

IntentActivity.java
package com.example.belajar_intent;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class IntentActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
}

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.belajar_intent">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.belajar_intent"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<activity android:name=".IntentActivity"/>
</application>

</manifest>

You might also like