Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Programming Basics

Android Programming Basics

Introduction to Android app development using Android Studio

Eueung Mulyana

August 28, 2017
Tweet

More Decks by Eueung Mulyana

Other Decks in Programming

Transcript

  1. 1 / 89 PPTB (ET-4044) Android Programming Basics Eueung Mulyana

    https://eueung.github.io/012017/android1 CodeLabs | Attribution-ShareAlike CC BY-SA
  2. Notes Android Studio 2.3.3 (Stable Channel) A copy of the

    latest OpenJDK comes bundled with Android Studio 2.2 and higher, and this is the JDK version recommended for your Android projects. Ref: [Con gure Android Studio] 3 / 89
  3. 5 / 89 What is Android Mobile operating system based

    on Linux kernel User Interface for touch screens Used on over 80% of all smartphones Powers devices such as watches, TVs, and cars Over 2 Million Android apps in Google Play store Highly customizable for devices / by vendors Open source Ref: Android Developer Fundamentals
  4. 7 / 89 Android Studio + Android SDK O cial

    Android IDE Develop, run, debug, test, and package apps Monitors and performance tools Virtual devices Project views Visual layout editor Ref: Android Developer Fundamentals
  5. 8 / 89 Logical Areas 1. Toolbar 2. Navigation Bar

    3. Editor Window 4. Tool Window Bar (Expand/Collapse) 5. Tool Window 6. Status Bar
  6. 9 / 89 Layout Editor Project Window (1) Palette of

    UI Elements (2) Selectors (3) Design Pane (6) Component Tree (7) Design/Text Tabs (8)
  7. 12 / 89 Android App One or more interactive screens

    Written using Java Programming Language and XML (*) Uses the Android Software Development Kit (SDK) Uses Android libraries and Android Application Framework Executed by Android Runtime Virtual machine (ART) Ref: Android Developer Fundamentals
  8. 13 / 89 Android Challenges Multiple screen sizes and resolutions

    Performance: make your apps responsive and smooth Security: keep source code and user data safe Compatibility: run well on older platform versions Marketing: understand the market and your users (Hint: It doesn't have to be expensive, but it can be.)
  9. 14 / 89 App Building Blocks Resources: layouts, images, strings,

    colors as XML and media les Components: activities, services,... and helper classes as Java code Manifest: information about app for the runtime Build con guration: APK versions in Gradle con g les
  10. 15 / 89 Component Types Activity is a single screen

    with a user interface Service performs long-running tasks in background Content provider manages shared set of data Broadcast receiver responds to system-wide announcements
  11. 16 / 89 Think of Android as a Hotel Your

    App is the guest The Android System is the hotel manager Services are available when you request them (Intents) In the foreground (Activities) such as registration In the background (Services) such as laundry Calls you when a package has arrived (Broadcast Receiver) Access the city's tour companies (Content Provider) Ref: Android Developer Fundamentals
  12. 18 / 89 Building Your First App 1. Create an

    Android Project 2. Run Your App 3. Build a Simple User Interface 4. Start Another Activity
  13. package com.example.em.exampleapplication01; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View;

    import android.widget.EditText; public class MainActivity extends AppCompatActivity { public static final String EXTRA_MESSAGE = "com.example.em.exampleapplication01.MESSAGE"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void sendMessage(View view) { Intent intent = new Intent(this, DisplayMessageActivity.class); EditText editText = (EditText) findViewById(R.id.editText); String message = editText.getText().toString(); intent.putExtra(EXTRA_MESSAGE, message); startActivity(intent); } } 80 / 89 MainActivity.java
  14. package com.example.em.exampleapplication01; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView;

    public class DisplayMessageActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); // Get the Intent that started this activity and extract the string Intent intent = getIntent(); String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); // Capture the layout's TextView and set the string as its text TextView textView = (TextView) findViewById(R.id.textView); textView.setText(message); } } 81 / 89 DisplayMessageActivity.java
  15. <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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="com.example.em.exampleapplication01.MainActivity">

    <EditText android:id="@+id/editText" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:ems="10" android:hint="@string/edit_message" android:inputType="textPersonName" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintRight_toLeftOf="@+id/button" android:layout_marginLeft="16dp" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:onClick="sendMessage" android:text="@string/button_send" app:layout_constraintBaseline_toBaselineOf="@+id/editText" app:layout_constraintLeft_toRightOf="@+id/editText" app:layout_constraintRight_toRightOf="parent" /> </android.support.constraint.ConstraintLayout> 83 / 89 activity_main.xml
  16. <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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="com.example.em.exampleapplication01.DisplayMessageActivity">

    <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="TextView" android:textAppearance="@style/TextAppearance.AppCompat.Display1" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> 84 / 89 activity_display_message.xml
  17. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.em.exampleapplication01"> <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=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".DisplayMessageActivity" android:parentActivityName=".MainActivity" </application> </manifest> 86 / 89 AndroidManifest.xml
  18. Refs/Resources 1. Getting Started | Android Developers 2. Dashboards |

    Android Developers 3. Android Developer Fundamentals | Google Developers Training | Google Developers 4. Introduction - Android Developer Fundamentals Course - Practicals 88 / 89