Introduction to android

Slides:



Advertisements
Similar presentations
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
Advertisements

The Android Activity Lifecycle. Slide 2 Introduction Working with the Android logging system Rotation and multiple layouts Understanding the Android activity.
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Android Life Cycle CS328 Dick Steflik. Life Cycle The steps that an application goes through from starting to finishing Slightly different than normal.
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Android Programming. Outline Preparation Create new project Build and Run a project Debug a project Deploy on devices.
Android Application Development 2013 PClassic Chris Murphy 1.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Better reference the original webpage :
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Getting Started with Android APIs Ivan Wong. Motivation - “Datasheet” - Recently exposed to what’s available in Android - So let’s see what API’s are.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
1 Mobile Computing Monetizing An App Copyright 2014 by Janson Industries.
Android Info mostly based on Pro Android 3.  User Applications  Java Libraries – most of Java standard edition ◦ Activities/Services ◦ UI/Graphics/View.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
DUE Hello World on the Android Platform.
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Android - Broadcast Receivers
Android – Fragments L. Grewe.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Android Hello World 1. Click on Start and type eclipse into the textbox 2.
Creating an Example Android App in Android Studio Activity lifecycle & UI Resources.
Cosc 4730 Android Fragments. Fragments You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
TODAY Android Studio Installation Getting started Creating your 1 st App Beginning to understanding Intents.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
INTRODUCTION TO ANDROID. Slide 2 Introduction I take a top-down approach to describing an application’s anatomy.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Android Programming.
Lab7 – Appendix.
Android Application -Architecture.
Mobile Application Development BSCS-7 Lecture # 2
Activity and Fragment.
several communicating screens
CS240: Advanced Programming Concepts
GUI Programming Fundamentals
Mobile Application Development Chapter 3 [Using Eclipse Android Studio for Android Development] IT448-Fall 2017 IT448- Fall2017.
Activities, Fragments, and Events
CS499 – Mobile Application Development
Mobile Application Development BSCS-7 Lecture # 6
Activities and Intents
Development-Introduction
Android Widgets 1 7 August 2018
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
The Android Activity Lifecycle
ANDROID UI – FRAGMENTS UNIT II.
Anatomy of an Android Application
Software Engineering for Internet Applications
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
Activities and Intents
Android Programming Tutorial
Programming Mobile Applications with Android
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Mobile Programming Dr. Mohsin Ali Memon.
SE4S701 Mobile Application Development
CMPE419 Mobile Application Development
Activities and Fragments
Activities, Fragments, and Intents
Mobile Programming Broadcast Receivers.
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Introduction to android David Sutton Start with class reference and download page open in browser

OUTLINE OF THE LECTURE Android basics Eclipse and the ADT plug in Android virtual devices Java revision Android programming concepts: Application, Activity, Intent, and View The Hello World Application Superclasses and subclasses Creating and editing the user interface

ANDROID BASICS Android is an open source operating system that runs on a wide variety of mobile devices with different properties. An android application is a combination of Java classes, XML files, and other resources such as images.

DEVELOPING ANDROID APPLICATIONS IN ECLIPSE Eclipse is an IDE (Integrated Development Environment) that allows you to develop software in Java and other programming languages. It has many of the same facilities as the NetBeans IDE with which you will be familiar. The ADT (Android Development Tools) plug in for Eclipse allows you to develop and emulate Android applications.

GETTING ECLIPSE AND THE ADT The Easy Way Download the “ADT Bundle” from http://developer.android.com/sdk This contains Eclipse with the ADT pre-installed. The Harder Way If you already have an installation of Eclipse on your computer, and don’t want to install another one, then you can download the ADT plug in separately. You download the ADT bundle from the same address as above (http://developer.android.com/sdk) but you need to follow the link marked “Use an Existing IDE).

WHAT DOES THE ADT DO FOR YOU? The ADT plug-in contains various special purpose editors to help you write Android apps. It also allows you to create an Android Virtual Device (AVD) and run your app on it.

WHY USE AN AVD? Installing and running an application on a virtual device is a bit fiddly and time consuming, but installing and running it on a real device is even more fiddly. It is easy to change the properties of a virtual device (for example the resolution). You can even create multiple AVDs with different properties, which is cheaper than buying lots of different phones.

JAVA REVISION (FOR STUDENTS WHO HAVE NOT TAKEN U08223). Primitive and reference types Classes, methods, and fields UML Public and private access

PRIMITIVE AND REFERENCE TYPES Primitive types: int, short, long, float, double, byte, char, boolean. Reference types: everything else. If a variable is of a primitive type then its value is a number, character, or boolean. If a variable is of a reference type then its value is a reference to a location on the heap. String s = new String("Jam"); int i = 42; Heap i = s = String “Jam” 42

CLASSES, FIELDS, AND METHODS This is a field. Each instance of the class has a different value for it. public class Person { private String name; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; This is a method. It is called on a particular instance of the class, and has access to the fields of that instance.

CLASSES IN UML Name of the class Person -name -age Fields. You can put in their types as well if you like. Or you can completely omit this compartment +getName +setName Methods. If you want you can put in the return type of the method, and the types of its parameters.

PUBLIC AND PRIVATE ACCESS A field or method with private access can only be referred to within the class in which it is defined. public class Person { private String name; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; A field or method with public access can be referred to anywhere in your code. If this code is outside of the Person class... This line is illegal because name has private access Person p = new Person(); p.name = "Joe"; p.setName("Joe"); This line is OK because setName has public access

ANDROID PROGRAMMING CONCEPTS An application may be associated with many Activities Activity An Intent is a message that may activate an Activity Application Intent View Activity An Activity represents a single screen with a user interface View View The user interface is built up from a set of Views. The user interface has one root view with any number of component views

CREATING THE HELLO WORLD APP

THE HELLO WORLD APP IN ECLIPSE The src folder contains Java classes that you write and edit yourself. The gen folder contains autogenerated Java classes. Don’t edit them. The res folder contains XML files and other resources, such as images.

THE MAIN ACTIVITY public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; The words underlined in red will be new to students who have not taken U08223. We will explain them in the next few slides.

SUPERCLASSES AND SUBCLASSES public class MainActivity extends Activity { Activity is a class that is built in to the Android API, in other words it is part of the stuff you get when you download Android. When we say that MainActivity extends Activity we are telling the compiler that MainActivity is a class that includes, or inherits, all of the methods and fields that are defined in Activity. Activity is a superclass of MainActivity, and MainActivity is subclass of Activity We can add extra fields or methods to the subclass. We can also modify the behaviour of methods from the superclass.

SUPERCLASSES AND SUBCLASSES Activity Activity contains over 100 methods. These are just 4 of them. addContentView getActionBar getMenuInflater onCreate This is the notation we use in UML to indicate that one class extends another. MainActivity inherits all of the methods of the Activity class. We generally do not repeat them here unless they have been overridden (in other words we have modified the way they behave). MainActivity onCreate

OVERRIDING AND THE “SUPER” KEYWORD MainActivity inherits an onCreate method from Activity. However we want to override it. In other words we want it to change the way it behaves. The overridden method must have exactly the same name and argument types as the method it overrides. public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } We want our overridden method to do everything that the superclass does, and then do some extra stuff. The line super.onCreate(savedInstanceState); means “do everything that the superclass version of onCreate does

The class reference To find a complete specification of the Activity class, or any other class, go to http://developer.android.com/reference/classes.html

INFLATING THE VIEW public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } This line creates the View that acts as the user interface for our Activity. It does this by “inflating” an XML file called activity_main.xml, which is located in the res/layout folder.

XML FILES Start tag <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" tools:context=".MainActivity" /> </RelativeLayout> Root element Start tag An element within another element Closing tags

INFLATING XML FILES <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" tools:context=".MainActivity" /> </RelativeLayout> RelativeLayout inflation TextView The layout file is inflated to create Java objects whose classes are specified by the XML elements. In this case we produce RelativeLayout object which acts a container into which we place a TextView object.

INFLATING AND DISPLAYING A LAYOUT FILE <RelativeLayout …> <TextView … android:text="@string/hello_world" … /> … </RelativeLayout> Layout file is inflated to create Java objects RelativeLayout TextView Java objects determine appearance of user interface for Activity

Editing layout (xml TAB) Click here to see a graphical view of the layout

Editing layout (graphical tab) You can drag elements into the layout from this palette Right click on an element within the layout to view and edit its properties

Editing layout You may find that it is easiest to switch between the two tabs depending on which is best for the particular task you wish to accomplish For example you might find it easiest to add elements and properties using the graphical tab, and then edit them in the XML tab.

THE MAIN ACTIVITY (RECAP) public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; For the time being, we will not worry about what this second overridden method does!

WHEN DOES THE ONCREATE METHOD GET CALLED? In U08004 and U08223 you generally created a main method for your programs, and therefore had control over when methods got called. Android applications do not work like that. The Android operating system decides when activities get started, stopped, and paused in response to user events and to the availability of memory and other resources. The onCreate method gets called when Android decides that the Activity ought to be created. There are many other “lifecycle” methods that behave in a similar way.

THE ACTIVITY LIFECYCLE Launched onCreate onStart onRestart onResume Killed Running onPause onStop Methods called as the Activity changes state onDestroy States of the Activity Shut Down

summary Android concepts Application: a collection of Activities (and other components that we will meet later) Activity: a single screen with a user interface View: a user interface component. The UI for an activity consists of a single root view, with many component views Intent: a way in which one Activity invokes another (to be covered in future lectures) Java concepts Subclasses inherit the fields and methods of their superclasses Methods may be overridden User interfaces Can be represented as XML files that are “inflated” into Java objects Activity life cycle State transitions controlled by Android OS Override methods that get called on state transition