• Tidak ada hasil yang ditemukan

Pertemuan 3 ARFIAN HIDAYAT, S.KOM

N/A
N/A
Protected

Academic year: 2021

Membagikan "Pertemuan 3 ARFIAN HIDAYAT, S.KOM"

Copied!
29
0
0

Teks penuh

(1)

Pertemuan 3

ARFIAN HIDAYAT, S.KOM

(2)

Pokok Bahasan

 GENYMotion

 Memahami Directori Android

 Kerangka Kerja Project Android

 Activity life cycle (onCreate, onDestroy, onPause, onStart, onResume, onRestart).

 Event Handling (onClick, onFocusChange, onKey, onTouch, onCreateContextMenu, dll)

(3)

Memahami Direktory Android

 Workspace

Lingkungan kerja Eclipse, meliputi area-area standart seperti direktori untuk project atau project explorer, menu atau toolbar, area editor, dan juga console debugging.

 Project Explorer

Direktori utama yang berada di lingkungan Eclipse. Sebuah folder project Eclipse yang

dipergunakan untuk pengembangan aplikasi Android, di dalamnya terdapat beberapa library, folder dan file pendukung lainnya.

(4)

Paket File Dan Folder Project

src/ folder src atau source memiliki fungsi sebagai tempat utama yang di dalamnya terdapat file-file Activity bertipe Java

Programming. File Activity ini terdiri dari beberapa Class yang menjadi logic dasar pemrograman aplikasi Android.

gen/ folder gen (Generated Java Files) mempunyai fungsi sebagai tempat untuk menggenerate file Java. Di dalamnya berisi Java Class yang dipergunakan untuk membantu Activity di dalam src/ folder.

Android 4.3 Folder Android 4.3 yang terletak di dalam project utama merupakan sebuah library yang dihasilkan saat kita

melakukan konfigurasi build target sistem. Jika kita melakukan

konfigurasi sistem menggunakan Build Target Android 2.3 misalnya, maka Library ini menyesuaikan dengan nama target tersebut. Folder ini merupakan virtual folder berisi file-file library .JAR

(5)

Paket File Dan Folder Project

Android Dependecies folder Android Dependencies berisi

library tambahan sebagai bagian dari project Android kita. Library tambahan ini dapat berisi Phonegap Library berbentuk .JAR.

assets/ folder folder assets memiliki fungsi yang hampir sama seperti src/ yaitu sebagai wadah paket yang akan di include ke aplikasi. Perbedaan mendasar antara src/ dan assets/ adalah kita tidak bisa otomatis meng-generate ID untuk konten-konten yang terletak di dalam /assets.

(6)

Paket File Dan Folder Project

bin/ folder Folder ini berisi file hasil dari pengkompilasian

Android. Saat kita sukses mengkompilasi atau membuild project Android, di dalam folder ini terdapat file .APK yang dapat langsung kita copy ke tempat lain dan siap pakai. File .APK ini terbentuk otomatis saat proses kompilasi berjalan sukses.

libs/ folder Folder ini berisi file berbentuk .JAR sebagai tempat library untuk fitur tambahan aplikasi. Folder ini biasanya dipakai saat aplikasi kita misalnya ingin diberi sebuah banner dari Admob. Maka sebelumnya developer harus memiliki file .JAR untuk Admob dan dimasukkan

langsung ke folder atau melalui menu Project Properties -> Java Build Path -> Libraries tab -> Add JARs.

(7)

Paket File Dan Folder Project

res/ folder Berisi berbagai resource atau

sumber-sumber untuk aplikasi seperti icon, splash screen, maupun string-string pendukung aplikasi. Di dalam folder ini terdiri dari beberapa subdirektori diantaranya

 /drawable folder yang berisi file gambar,

 /layout folder berisi file main.xml untuk mengatur tata letak dan tampilan utama aplikasi Android,

 /values folder yang berisi string teks utama aplikasi,  dan /xml folder untuk string tertentu

(8)

Paket File Dan Folder Project

AndroidManifest.xml

merupakan file yang berfungsi untuk

menggambarkan

karakteristik mendasar dari aplikasi dan mendefinisikan masing-masing komponen aplikasi. Di dalamnya

terdapat source code elemen-elemen untuk

mendeklarasikan fitur-fitur tertentu di dalam aplikasi.

(9)

A simplified illustration of the Activity

lifecycle

(10)

Activity Life Cycle

onCreate() method ini dipanggil saat activity pertama kali dibuat. Di sinilah inisialisasi dilakukan – membuat UI, mendapatkan data yang diperlukan, dan lainnya.

onStart() method ini dipanggil sesaat sebelum activity ditampilkan ke pengguna.

onResume() method ini dipanggil ketika activity berinteraksi dengan pengguna.

onPause() method ini berjalan ketika activity berada di balik layar (background), tidak terlihat oleh pengguna tapi masih berjalan. Biasanya hal ini terjadi saat ada activity lainnya yang

dijalankan. Di state inilah seharusnya data program kita disimpan ke persistent state.

onStop() method ini berjalan ketika activity sudah tidak terlihat lagi oleh pengguna dalam waktu yang cukup lama dan activity tidak diperlukan untuk sementara waktu.

onRestart() jika method ini dipanggil, berarti activity sedang ditampilkan ulang ke pengguna dari state berhenti (stop).

(11)

Event

Event adalah sesuatu yang terjadi dari? luar?, sesuatu yang tidak kita kontrol dan sesuatu yang kita tidak tahu kapan akan terjadi. Untuk itu kita menggunakan Events Controllers untuk setiap event yang bisa terjadi. Ada beberapa macam Event Controller seperti Event Listener, Event Handler, Touch Mode dan Handling focus

Event Listener adalah sebuah objek yang diberitahu pada saat suatu event terjadi pada event source. Event listener diimplementasikan ke dalam bentuk method dalam suatu

interface. Berikut ini method method yang termasuk event listener userinterface:

◦ onCLick(), ◦ onLongClick(), ◦ onFocusChange(), ◦ onKey(), ◦ onTouch(), ◦ onCreateContextMenu()

(12)

Event Handling

Event adalah sebuah message yang dikirim oleh sebuah object untuk menandai kejadian sebuah aksi. Handler adalah sebuah method yang akan diisikan (atau diikatkan) pada event. Jadi event handler adalah suatu fungsi atau method yang mengandung statement program untuk

menangani input yang diterima ke dalam event. Berikut ini merupakan method ? method event handling :  onKeyUp()  onKeyDown()  onTrackballEvent()  onTouchEvent()  onFocusChanged()

(13)

Intent

Intent adalah suatu objek yang terdapat dalam suatu activity dimana dengan objek tersebut bisa melakukan komunikasi dengan activity lain, baik activity yang sudah terdapat pada fungsi internal android (Browser, kamera, dll) ataupun memanggil activity lain yang terdapat dalam satu package ataupun beda package dalam satu projek.

Intent Types

 Implicit intent merupakan intent yang memanggil fungsi yang sudah ada pada fungsi internal android.

(14)

Intent Implicit

Illustration of how an implicit intent is delivered through the system to start another activity:

1. Activity A creates an Intent with an action description and passes it to startActivity(). 2. The Android System

searches all apps for an intent filter that

matches the intent. When a match is found, 3. the system starts the

matching activity

(Activity B) by invoking its onCreate() method and passing it the Intent.

(15)

Building an Intent

An Intent object carries information that the Android system uses to determine which

component to start (such as the exact component name or component category that should receive the intent), plus information that the recipient component uses in order to properly perform the action (such as the action to take and the data to act upon).

The primary information contained in an Intent is the following:

 Component name : The name of the component to start.

 Action : A string that specifies the generic action to perform (such as view or pick). ◦ static final String ACTION_TIMETRAVEL = "com.example.action.TIMETRAVEL";

 Data

◦ The URI (a Uri object) that references the data to be acted on and/or the MIME type of that data. The type of data supplied is generally dictated by the intent's action. For example, if the action is ACTION_EDIT, the data should contain the URI of the document to edit.

(16)

Building an Intent

The primary information contained in an Intent is the following:  Category

 A string containing additional information about the kind of component that should handle the intent.

 CATEGORY_BROWSABLE The target activity allows itself to be started by a web browser to display data referenced by a link—such as an image or an e-mail message.

 CATEGORY_LAUNCHER The activity is the initial activity of a task and is listed in the system's application launcher.

 Extras

 Bundle informasi tambahan

 Sebagai contoh, jika kita memiliki action untuk mengirim pesan e-mail , kita bisa juga melakukan tambahan data untuk mengisi subjek , body , dll

 Flags

 berfungsi sebagai metadata

(17)

Example Explicit Intent

An explicit intent is one that you use to launch a specific app component, such as a particular activity or service in your app. To create an explicit intent, define the component name for the Intent object—all other intent properties are optional.

(18)
(19)

Forcing an app chooser

For example, when your app performs "share" with the

ACTION_SEND action, users may want to share using a different app depending on their current situation, so you should always use the chooser dialog, as shown in figure

(20)

Receiving an Implicit Intent

To advertise which implicit intents your app can receive, declare one or more intent filters for each of your app components with an <intent-filter> element in your manifest file.

Komponen aplikasi harus menyatakan filter terpisah untuk setiap pekerjaan yang unik yang dapat dilakukan .

◦ Misalnya, satu kegiatan dalam sebuah aplikasi galeri gambar memiliki dua filter : satu filter untuk

melihat gambar , dan filter lain untuk mengedit gambar . Ketika kegiatan dimulai , ia memeriksa Intent dan memutuskan bagaimana berperilaku berdasarkan informasi dalam Intent ( seperti untuk

(21)

Example Intent-Filter

<action>

Declares the intent action accepted, in the name attribute. The value must be the literal string value of an action, not the class constant.

<data>

Declares the type of data accepted, using one or more attributes that specify various aspects of the data URI (scheme, host, port, path, etc.) and MIME type.

<category>

Declares the intent category accepted, in the name attribute. The value must be the literal string value of an action, not the class constant.

Note: In order to receive implicit intents, you must include the

CATEGORY_DEFAULT category in the intent filter. If you do not declare this category in your intent filter, no implicit intents will resolve to your activity.

(22)

Using a Pending Intent

PendingIntent adalah pembungkus obyek Intent. Tujuan utama dari PendingIntent adalah memberikan izin kepada aplikasi asing untuk menggunakan Intent yang ada seolah-olah itu dijalankan dari proses aplikasi Anda sendiri.

Kasus penggunaan utama PendingIntent meliputi:

◦ Declare an intent to be executed when the user performs an action with your Notification (the Android system's NotificationManager executes the Intent).

◦ Declare an intent to be executed when the user performs an action with your App Widget (the Home screen app executes the Intent).

◦ Declare an intent to be executed at a specified time in the future (the Android system's AlarmManager executes the Intent).

(23)

Intent Resolution

When the system receives an implicit intent to start an activity, it searches for the best activity for the intent by comparing the intent to intent filters based on three aspects:

◦ The intent action

◦ The intent data (both URI and data type)

◦ The intent category Action Test

(24)

Intent Resolution

 Category Test

Data Test

Android secara otomatis menerapkan kategori

CATEGORY_DEFAULT untuk semua intent implisit

dilewatkan ke startActivity () dan startActivityForResult (). Setiap elemen <data>

dapat menentukan struktur URI dan tipe data (MIME jenis media). Ada atribut yang terpisah - scheme, host, port, and path

<scheme>://<host>:<port> /<path>

(25)

Example URI

content://com.example.project:200/folder/subfolder/etc

In this URI, the scheme is content, the host is com.example.project, the port is 200, and the path is folder/subfolder/etc.

Each of these attributes is optional in a <data> element, but there are linear dependencies:

◦ If a scheme is not specified, the host is ignored.

◦ If a host is not specified, the port is ignored.

◦ If both the scheme and host are not specified, the path is ignored.

When the URI in an intent is compared to a URI specification in a filter, it's compared only to the parts of the URI included in the filter. For example:

◦ If a filter specifies only a scheme, all URIs with that scheme match the filter.

◦ If a filter specifies a scheme and an authority but no path, all URIs with the same scheme and authority pass the filter, regardless of their paths.

◦ If a filter specifies a scheme, an authority, and a path, only URIs with the same scheme, authority, and path pass the filter. Note: A path specification can contain a wildcard asterisk (*) to require only a partial match of the path name.

(26)

Compare URI & MIMEType

The data test compares both the URI and the MIME type in the intent to a URI and MIME type specified in the filter. The rules are as follows:

a. An intent that contains neither a URI nor a MIME type passes the test only if the filter does not specify any URIs or MIME types.

b. An intent that contains a URI but no MIME type (neither explicit nor inferable from the URI) passes the test only if its URI matches the filter's URI format and the filter likewise does not specify a MIME type.

c. An intent that contains a MIME type but not a URI passes the test only if the filter lists the same MIME type and does not specify a URI format.

d. An intent that contains both a URI and a MIME type (either explicit or inferable from the URI) passes the MIME type part of the test only if that type matches a type listed in the filter. It passes the URI part of the test either if its URI matches a URI in the filter or if it has a content: or file: URI and the filter does not specify a URI. In other words, a component is presumed to support

(27)

Compare URI & MIMEType

Aturan (d), mencerminkan harapan bahwa komponen bisa mendapatkan data lokal dari sebuah file atau konten provider. Oleh karena itu, filter yang bisa daftar hanya tipe data dan tidak perlu secara eksplisit menamakan konten: dan file: skema. Ini adalah kasus yang khas. Unsur <data> seperti berikut, misalnya, mengatakan bahwa Android komponen bisa mendapatkan data

gambar dari penyedia konten dan menampilkannya:

Karena data yang paling tersedia akan dibagikan oleh penyedia konten, filter yang menentukan tipe data tapi bukan URI mungkin adalah yang paling umum.

(28)

Compare URI & MIMEType

Konfigurasi umum lainnya adalah filter dengan skema dan tipe data. Sebagai contoh, elemen <data> seperti berikut memberitahu Android bahwa komponen dapat mengambil data video dari jaringan untuk melakukan tindakan:

(29)

Sumber

 http://www.scribd.com /doc/191991516/Modul-2-Android

 http://developer.android.com/guide/components/activities.html

Gambar

Illustration of how an implicit intent is delivered through the  system to start another activity:

Referensi

Dokumen terkait

Menurut Hellier, et al, (2003) dalam Setyaningsih (2008) niat beli ulang merupakan keputusan konsumen untuk melakukan pembelian kembali suatu produk atau

modeling siswa dapat diajak untuk mempelajari perilaku-perilaku baru yang akan diberikan oleh model. Di sini peran modeling adalah untuk membina melalui latihan, pendidikan,

Pada dasarnya stainless steel merupakan salah satu jenis dari baja paduan, sehingga pembuatan stainless steel tidak jauh berbeda dengan proses pembuatan baja paduan, yang

DASHBOARD SDMK 2 - PERENCANAAN KEBUTUHAN SDMK DI PUSKESMAS &lt;=== NAMA KABUPATEN/KOTA JENIS TENAGA SESUAI STANDAR 1.

Dokumentasi Pribadi Alat Penelitian: Aerator Gelas Ukur 1000 ml Timbangan Digital Terminal Listrik. Ammonia Test Kit

Variabel ukuran perusahaan diperoleh memiliki pengaruh positif terhadap CSR.Hasil penelitian ini memberikan dukungan empiris bahwa perusahaan yang besar lebih banyak memiliki

2) Kontrak Harga Satuan adalah kontrak pengadaan barang/jasa atas penyelesaian seluruh pekerjaan dalam batas waktu tertentu, berdasarkan harga satuan yang pasti dan

 Diberikan data hasil percobaan, secara mandiri siswa dapat membuat laporan percobaan tentang sifat fisik dan sifat kimia unsur golongan alkali, alakali tanah, gas mulia,