Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Similar documents
Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

Android Application Development. By : Shibaji Debnath

Java & Android. Java Fundamentals. Madis Pink 2016 Tartu

Android HelloWorld - Example. Tushar B. Kute,

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen

CPET 565 Mobile Computing Systems CPET/ITC 499 Mobile Computing. Lab & Demo 2 (Part 1-2) Hello-Goodbye App Tutorial

Android Exam AND-401 Android Application Development Version: 7.0 [ Total Questions: 129 ]

Android UI Development

Overview. What are layouts Creating and using layouts Common layouts and examples Layout parameters Types of views Event listeners

Mobila applikationer och trådlösa nät, HI1033, HT2012

LifeStreet Media Android Publisher SDK Integration Guide

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

INTRODUCTION TO ANDROID

Solving an Android Threading Problem

Mobila applikationer och trådlösa nät, HI1033, HT2013

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

Software Practice 3 Before we start Today s lecture Today s Task Team organization

Android development. Outline. Android Studio. Setting up Android Studio. 1. Set up Android Studio. Tiberiu Vilcu. 2.

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters

EMBEDDED SYSTEMS PROGRAMMING Application Basics

Hello World. Lesson 1. Android Developer Fundamentals. Android Developer Fundamentals. Layouts, and. NonCommercial

Embedded Systems Programming - PA8001

Android Basics. Android UI Architecture. Android UI 1

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

Gauthier Picard. MINES Saint-Étienne. October 10, 2017

Fragments. Lecture 11

Android Application Development

Programming with Android: Introduction. Layouts. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Mobile Computing Fragments

An Overview of the Android Programming

IPN-ESCOM Application Development for Mobile Devices. Extraordinary. A Web service, invoking the SOAP protocol, in an Android application.

Getting started: Installing IDE and SDK. Marco Ronchetti Università degli Studi di Trento

Upon completion of the second part of the lab the students will have:

Created By: Keith Acosta Instructor: Wei Zhong Courses: Senior Seminar Cryptography

Embedded Systems Programming - PA8001

Screen Slides. The Android Studio wizard adds a TextView to the fragment1.xml layout file and the necessary code to Fragment1.java.

Security model. Marco Ronchetti Università degli Studi di Trento

CPET 565 Mobile Computing Systems CPET/ITC 499 Mobile Computing. Lab & Demo 2 (1 &2 of 3) Hello-Goodbye App Tutorial

Group B: Assignment No 8. Title of Assignment: To verify the operating system name and version of Mobile devices.

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Adapter.

CS 528 Mobile and Ubiquitous Computing Lecture 2a: Android UI Design in XML + Examples. Emmanuel Agu

Gauthier Picard. Ecole Nationale Supérieure des Mines

Computer Science E-76 Building Mobile Applications

Real-Time Embedded Systems

Fragment Example Create the following files and test the application on emulator or device.

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

Mobile User Interfaces

Tutorial: Setup for Android Development

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

EMBEDDED SYSTEMS PROGRAMMING Android Services

UNDERSTANDING ACTIVITIES

Android Beginners Workshop

Creating a Custom ListView

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

Android Basics. - Bhaumik Shukla Android Application STEALTH FLASH

Activities and Fragments

Mobile Programming Lecture 1. Getting Started

Intents. Your first app assignment

Multiple Activities. Many apps have multiple activities

Fragments. Lecture 10

LECTURE NOTES OF APPLICATION ACTIVITIES

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Android Workshop: Model View Controller ( MVC):

Android framework overview Activity lifecycle and states

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Android. Mobile operating system developed by Google A complete stack. Based on the Linux kernel Open source under the Apache 2 license

Android Layout Types

ANDROID USER INTERFACE

Tutorial: Setup for Android Development

Android & iphone. Amir Eibagi. Localization

Vienos veiklos būsena. Theory

Thread. A Thread is a concurrent unit of execution. The thread has its own call stack for methods being invoked, their arguments and local variables.

Notification mechanism

Mobile and Ubiquitous Computing: Android Programming (part 3)

CS 370 Android Basics D R. M I C H A E L J. R E A L E F A L L

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

Tablets have larger displays than phones do They can support multiple UI panes / user behaviors at the same time

8/30/15 MOBILE COMPUTING. CSE 40814/60814 Fall How many of you. have implemented a command-line user interface?

Android Specifics. Jonathan Diehl (Informatik 10) Hendrik Thüs (Informatik 9)

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

<uses-permission android:name="android.permission.internet"/>

South Africa

Mobile Development Lecture 10: Fragments

Chapter 5 Flashing Neon FrameLayout

Mobile Programming Practice Background processing AsynTask Service Broadcast receiver Lab #5

UI (User Interface) overview Supporting Multiple Screens Touch events and listeners

Learn about Android Content Providers and SQLite

MODULE 2: GETTING STARTED WITH ANDROID PROGRAMMING

Android Navigation Drawer for Sliding Menu / Sidebar

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

Android Programming Lecture 2 9/7/2011

Arrays of Buttons. Inside Android

Developing For Android

Android - Widgets Tutorial

PROGRAMMING APPLICATIONS DECLARATIVE GUIS

Manifest.xml. Activity.java

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Android

Android Programming - Jelly Bean

ActionBar. import android.support.v7.app.actionbaractivity; public class MyAppBarActivity extends ActionBarActivity { }

Transcription:

Diving into Android By Jeroen Tietema Jeroen Tietema, 2015 1

Requirements 4 Android SDK 1 4 Android Studio (or your IDE / editor of choice) 4 Emulator (Genymotion) or a real device. 1 See https://developer.android.com Jeroen Tietema, 2015 2

Structure of an Android project <rootfolder> + app + src \ main + assets + java + res \ AndroidManifest.xml \ build.gradle + gradle + build.gradle + gradlew + gradlew.bat \ settings.gradle Jeroen Tietema, 2015 3

Overview of Android components 4 Intents : used to communicate actions or events 4 Activities : a screen 4 Services : a background process 4 BroadcastReceivers : subscribing to broadcasts from android or other apps 4 ContentProvider : share data across apps Jeroen Tietema, 2015 4

AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp"> <uses-permission android:name="android.permission.internet" /> <uses-sdk android:minsdkversion="11" android:targetsdkversion="21" /> <application android:name=".myapplication" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme"> // application components go here </application> </manifest> Jeroen Tietema, 2015 5

AndroidManifest.xml (cont.) <activity android:name=".myactivity"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> Jeroen Tietema, 2015 6

Activities Jeroen Tietema, 2015 7

class MyActivity extends Activity { @Override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.my_layout); } } @Override protected void onsaveinstancestate(bundle outstate) { super.onsaveinstancestate(outstate); // save your state } Jeroen Tietema, 2015 8

Life-cycle methods * oncreate(bundle) * onstart() * onresume() * onpause() * onstop() * ondestroy() See javadoc of Activity Jeroen Tietema, 2015 9

Launching Intent myintent = new Intent(context, MyActivity.class); context.startactivity(myintent); Stopping activity.finish(); Jeroen Tietema, 2015 10

XML Layouts Jeroen Tietema, 2015 11

src/main/res/layout/my_layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello, I am a TextView" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello, I am a Button" /> </LinearLayout> Jeroen Tietema, 2015 12

Working with your Views in Java code protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.my_layout); TextView mytext = (TextView) findviewbyid(r.id.text); Button mybutton = (Button) findviewbyid(r.id.button); } mytext.settext("hello world!"); mybutton.setonclicklistener(this); Jeroen Tietema, 2015 13

Widgets 4 Button 4 TextView 4 ProgressBar 4 ImageView 4 Checkbox 4 RadioButton Jeroen Tietema, 2015 14

Layouts 4 LinearLayout 4 RelativeLayout 4 FrameLayout 4 ViewPager 4 AdapterView 4 RecycleView Jeroen Tietema, 2015 15

Resources Jeroen Tietema, 2015 16

res + drawable + drawable-xhpdi + drawable-xxhdpi-land + drawable-nodpi + layout + layout-land + layout-sw600dp + values + values-nl \ values-v21 Jeroen Tietema, 2015 17

Density independent pixels 1dp = 1 pixel on a 160 dpi screen. This is called a mdpi screen. mdpi = 1 pixel hdpi = 1.5 pixels xhdpi = 2 pixels xxhdpi = 3 pixels xxxhdpi = 4 pixels Jeroen Tietema, 2015 18

Using resources (drawables) Given that you have a drawable res/drawable/icon.png myimageview.setimageresource(r.drawable.icon); Android will automatically pick the right resources from the most appropriate folder. Jeroen Tietema, 2015 19

Using resources (strings) <resources> <string name="hello_world">hello world!</string> <string> mytext.settext(r.string.hello_world); Jeroen Tietema, 2015 20

ListViews and Adapters Jeroen Tietema, 2015 21

View reuse Jeroen Tietema, 2015 22

BaseAdapter class MyAdapter extends BaseAdapter { public int getcount() {} public Object getitem(int position) {} public long getitemid(int position) {} } public View getview(int position, View convertview, ViewGroup parent) {} Jeroen Tietema, 2015 23

Multiple view types Jeroen Tietema, 2015 24

Multiple view types public int getviewtypecount() {} public int getviewtype(int position) {} Android will make sure you get back the correct View in your convertview. Jeroen Tietema, 2015 25

Concurrency Jeroen Tietema, 2015 26

The UI / Main Thread 4 60 fps == 16 ms per frame 4 Blocking the UI thread for more than a couple of seconds pops the "This app is not responding" dialog 4 No disk or network IO on the main thread 4 Loading Bitmaps straight into right resolution minimizes GC Jeroen Tietema, 2015 27

Threading constructs 4 Everything from Java (1.6) 4 AsyncTask 4 IntentService 4 Handler Jeroen Tietema, 2015 28

AsyncTask class MyTask extends AsyncTask<String, Void, Bitmap> { public void onpreexecute() { // called on UI thread } pubic Bitmap doinbackground(string... args) { // called in Background } } public void onpostexecute(bitmap result) { // called on UI thread } Jeroen Tietema, 2015 29

IntentService class MyIntentService extends IntentService { protected void onhandleintent(intent i) { } // this is on the background thread! } Jeroen Tietema, 2015 30

Handlers Handlers are bound to the Thread you create them on (if you don't explicitly specify one). Works only if the Thread has a Looper. You can use them to: 4 post message / runnables to a different thread 4 schedule runnables in the future. Jeroen Tietema, 2015 31

Questions? Just ask jeroen@tietema.net Jeroen Tietema, 2015 32