Membuat Intent di Android Studio
hello temen2,
sekarang kita akan membuat perpindahan antara activity atau yang lebih terkenal dengan kata intent..
kita akan membuat layout pertama
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frame_container">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btn_pindah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pindah Activity" />
<Button
android:id="@+id/btn_dial_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Dial a Number"/>
<Button
android:id="@+id/btn_browser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ke Browser"/>
</LinearLayout>
</FrameLayout>
kemudian kita buat layout kedua...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".PindahActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ini Pindah Activity"
android:gravity="center"
android:textSize="15pt"/>
</LinearLayout>
dan terakhir kita mengatur di android manifestnya..
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.projekintent">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".PindahActivity"
android:parentActivityName=".MainActivity"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
bila selesai maka akan tampil seperti berikut...
contoh intent explisit

bila tombol pindah activity di tekan maka dia akan pindah ke activity ini..
contoh intent implisit

bila tombol dial number ditekan maka akan pindah ke activity diluar aplikasi..
Komentar
Posting Komentar