2 - Android Development App 1
2 - Android Development App 1
Pertemuan – 2
Development process for an Android app
Android
WHAT IS ANDROID?
Binary Assets
Configuration Files
Layout in Android
An XML‐based layout is a specification of the
various UI components (widgets) and the
relationships to each other –and to their
containers –all written in XML format.
[email protected] res/layout
Attaching Layouts to Java Code
XML to Java
public class Main extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Attaching Layouts to Java Code - 2
Main.java
R.java
Main.xml
<TextView
android:id="@+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world“
/>
Strings.xml
<resources>
<string name="app_name">AKDip</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
</resources>
Variable in Activity from Layout
XML to Java (Ex. TextView)
Main.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
R.java
public static final class id {
public static final int TextView1=0x7f080003;
}
Variable in Activity from Layout
XML to Java (Ex. Button)
Main.xml
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tombol“
android:onClick=“saatTombolDitekan”
/>
Main.java
public void saatTombolDitekan(View v) {
Button bt = (Button) findViewById(R.id.button1);
bt.setText("Hello new World");
}
Android Activity
Lifecycle
onCreate() Called when the activity is first created.
This is where you should do all of your normal static
set up create views, bind data to lists, and so on.
onStart() Called just before the activity becomes
visible to the user.
onRestart() Called after the activity has been
stopped, just prior to it being started again.
onResume() Called just before the activity starts
interacting with the user.
onPause() Called when the system is about to start
resuming another activity.
onStop() Called when the activity is no longer
visible to the user.
onDestroy() Called before the activity is destroyed.
Source :
Debug and Testing
http://developer.android.com/about/dashboards/index.html
http://developer.android.com/guide/practices/screens_suppor
Publishing
play.google.com/apps/publish
Thank you
Andika Sundawijaya
[email protected]