Tutorial Programming

Tutorial Intent Pada Android


Hallo sahabat saya akan menjelaskan tentang apa sih intent di android, nah ini menurut saya yah, intent itu, misalkan kita mau ke warung pak mamat dan kembali lagi ke rumah gimana cara nya, hehehe kira-kira itu logika nya, dalam contoh kasus misal di HTML , sahabat mau ke page home, lalu ingin ke about, nah intent itu kira-kira seperti itu. oke langsung aja kita belajar coding nya gimana? 

1. Buatlah project android kalian

2. Lalu copy coding MainActivity.java tersebut

package com.example.tutorintent;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

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


    public void NahIniAbout(View view) {
        Intent objIntent = new Intent(getApplicationContext(), About.class);
        startActivity(objIntent);
    }
    
    public void BalekOy(View view) {
        Intent objIntent = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(objIntent);
    }
    
}


3. Lalu buat class lagi di dalam project kalian, yang setarap MainActivity.java , misalnya kalau saya membuat About.java

4. selanjutnya copy coding About.java tersebut

package com.example.tutorintent;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;

public class About extends Activity {

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


    public void NahIniAbout(View view) {
        Intent objIntent = new Intent(getApplicationContext(), About.class);
        startActivity(objIntent);
    }
    
    public void BalekOy(View view) {
        Intent objIntent = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(objIntent);
    }
    
}


5. copy coding activity_main.xml tersebut

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:onClick="BalekOy"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="67dp"
        android:text="Home" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="37dp"
        android:onClick="NahIniAbout"
        android:text="About" />

</RelativeLayout>

6. Buat layout baru dengan nama about.xml di res/layout/about.xml misalkan.

7. lalu copy coding tersebut di about.xml

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="About Ary EJFA" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:onClick="BalekOy"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="67dp"
        android:text="Home" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="37dp"
        android:onClick="NahIniAbout"
        android:text="About" />

</RelativeLayout>

8. Setelah itu copy coding AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.tutorintent"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="10" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.tutorintent.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>


9. Lalu run aplikasi kalian.

10. Oke seleseai project intent kalian sahabat.






Sekian tutorial saya semoga bermanfaat

No comments:

Post a Comment

Tutorial Programming Designed by Templateism | Ary EJFA Copyright © 2015

Theme images by richcano. Powered by Blogger.