Free Download Software and Android Tutorials

Friday, July 31, 2015

Basic Android studio tutorial: Know Activity on programming Android

Android studio tutorial will discuss about the activity on android-based programming language. I hope you understand what it is about the layout, the objects are often used in making Android-based application that we are familiar with a graphical user interface that I wrote in a previous tutorial, if you have not been able to learn the article I read that part of the Graphic user interface and part two graphical user interfaces. Every android application must have had at least one activity, perhaps in one application has more than one activity. All activities are used in the application must be included in AndroidManifest.xml.

Activity is an object that regulates activity cycles in an android application layout, which is usually in an activity is usually at least one subroutine is redefined with @Override command, namely onCreate. This subroutine is used to initialize variables and determine the display screen towards layout.xml which. To be clearer to understand this activity, I will give an example in the form of switching between layouts with different content, which is required of each activity for each layout. Make a project of your studio android and name PindahActivity, where this project consists of:
  • PertamaActivity.java
  • KeduaActivity.java
  • activity_pertama.xml
  • activity_kedua.xml
  • AndroidManifest.xml
Source code PertamaActivity.java
package com.dsoccerupdate.pindahactivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;

public class PertamaActivity extends Activity {
    Button button;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pertama);
        addListenerOnButton();
    }
    public void addListenerOnButton() {
        final Context context = this;
        button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent intent = new
                        Intent(context, KeduaActivity.class);
                startActivity(intent);
            }
        });
    }
}

Source code KeduaActivity.java
package com.dsoccerupdate.pindahactivity;

/**
 * Created by epsbed on 8/1/2015.
 */
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;

public class KeduaActivity extends Activity{
    Button button;

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

Source code activity_pertama.xml
<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Di Activity Pertama"
        android:textAppearance="?android:textAppearanceLarge"/>

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Click untuk ke Activity lain"/>
</LinearLayout>

Source activity_kedua.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Di activity kedua"/>

</LinearLayout>

Source code AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.dsoccerupdate.pindahactivity">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".PertamaActivity"
            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:label="@string/app_name"
            android:name=".KeduaActivity">

        </activity>
    </application>

</manifest>

basic, android, studio, tutorial, activity, programming, android

basic, android, studio, tutorial, activity, programming, android

That is a brief explanation basic android studio tutorial for a discussion to know Activity on android-based programming, hopefully this short article can provide a more in-depth knowledge for those of you who are studying the android-based programming language. Follow the tutorial article continues android studio, because I will continue to provide material about the world of android just for you.

Basic Android studio tutorial: Know Activity on programming Android Rating: 4.5 Diposkan Oleh: Unknown

0 comments:

Post a Comment