EMBEDDED SYSTEMS PROGRAMMING Application Basics

Similar documents
EMBEDDED SYSTEMS PROGRAMMING Android NDK

EMBEDDED SYSTEMS PROGRAMMING Android NDK

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

EMBEDDED SYSTEMS PROGRAMMING Android NDK

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

android-espresso #androidespresso

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

Mobile Application Development

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

Developing For Android

Android Basics. Android UI Architecture. Android UI 1

EMBEDDED SYSTEMS PROGRAMMING Android Services

Android Fundamentals - Part 1

Android Application Development

UNDERSTANDING ACTIVITIES

Android HelloWorld - Example. Tushar B. Kute,

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

Overview of Activities

Applications. Marco Ronchetti Università degli Studi di Trento

CS 4518 Mobile and Ubiquitous Computing Lecture 4: Data-Driven Views, Android Components & Android Activity Lifecycle Emmanuel Agu

Activities. Repo:

CS 528 Mobile and Ubiquitous Computing Lecture 3b: Android Activity Lifecycle and Intents Emmanuel Agu

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

LECTURE NOTES OF APPLICATION ACTIVITIES

Real-Time Embedded Systems

LifeStreet Media Android Publisher SDK Integration Guide

IEMS 5722 Mobile Network Programming and Distributed Server Architecture

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

Computer Science E-76 Building Mobile Applications

Android System Architecture. Android Application Fundamentals. Applications in Android. Apps in the Android OS. Program Model 8/31/2015

Lifecycle Callbacks and Intents

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

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

CS 528 Mobile and Ubiquitous Computing Lecture 3: Android UI, WebView, Android Activity Lifecycle Emmanuel Agu

This document providesanoverview ofthestepsrequired to implement an android app which will call the ACH android SDK.

Activities and Fragments

Android tips. which simplify your life

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Embedded Systems Programming - PA8001

Getting Started With Android Feature Flags

CS378 - Mobile Computing. Anatomy of an Android App and the App Lifecycle

Introduction To Android

Introduction to Android

Security model. Marco Ronchetti Università degli Studi di Trento

Fragments were added to the Android API in Honeycomb, API 11. The primary classes related to fragments are: android.app.fragment

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

Android Basics. - Bhaumik Shukla Android Application STEALTH FLASH

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

Vienos veiklos būsena. Theory

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

Google Maps Troubleshooting

States of Activities. Active Pause Stop Inactive

Lab 1: Getting Started With Android Programming

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

EMBEDDED SYSTEMS PROGRAMMING UI and Android

Introduction to Android Development

The Definitive Guide to Firebase

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

CSCU9YH Development with Android

COSC 3P97 Mobile Computing

05. RecyclerView and Styles

CS378 -Mobile Computing. Anatomy of and Android App and the App Lifecycle

COLLEGE OF ENGINEERING, NASHIK-4

MODULE 2: GETTING STARTED WITH ANDROID PROGRAMMING

Android Ecosystem and. Revised v4presenter. What s New

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

1.1 Why Foxit MobilePDF SDK is your choice Foxit MobilePDF SDK Key Features Evaluation License...

UI Fragment.

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Android Overview. Most of the material in this section comes from

Multiple Activities. Many apps have multiple activities

Android for Ubiquitous Computing Researchers. Andrew Rice University of Cambridge 17-Sep-2011

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

Lifecycle-Aware Components Live Data ViewModel Room Library

1.1 Why Foxit MobilePDF SDK is your choice Foxit MobilePDF SDK Key Features Evaluation License...

INTRODUCTION TO ANDROID

Solving an Android Threading Problem

Introduction to Android

App Development for Android. Prabhaker Matet

Android App Development. Muhammad Sharjeel COMSATS Institute of Information Technology, Lahore

CMSC436: Fall 2013 Week 3 Lab

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

Android Beginners Workshop

Introduction to Android development

Create new Android project in Android Studio Add Button and TextView to layout Learn how to use buttons to call methods. Modify strings.

PROGRAMMING APPLICATIONS DECLARATIVE GUIS

VMware AirWatch Android SDK Technical Implementation Guide Empowering your enterprise applications with MDM capabilities using

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

Lecture 2 Android SDK

CS 4518 Mobile and Ubiquitous Computing Lecture 5: Rotating Device, Saving Data, Intents and Fragments Emmanuel Agu

Android Application Development. By : Shibaji Debnath

Programming with Android: System Architecture. Dipartimento di Scienze dell Informazione Università di Bologna

1 카메라 1.1 제어절차 1.2 관련주요메서드 1.3 제작철차 서피스뷰를생성하고이를제어하는서피스홀더객체를참조해야함. 매니페스트에퍼미션을지정해야한다.

Android Workshop: Model View Controller ( MVC):

VMware Workspace ONE SDK for Android Integration Instructions. VMware Workspace ONE UEM

Minds-on: Android. Session 2

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

Android Software Development Kit (Part I)

Questions and Answers. Q.1) Which of the following is the most ^aeuroeresource hungry ^aeuroepart of dealing with activities on android?

Transcription:

EMBEDDED SYSTEMS PROGRAMMING 2015-16 Application Basics

APPLICATIONS Application components (e.g., UI elements) are objects instantiated from the platform s frameworks Applications are event driven ( there are callbacks, delegates, notifications...) Many use design patterns (e.g., delegation, model-view-controller,...)

APPLICATIONS AND IDES Integrated Development Environments (IDEs) simplify application development by automatically setting up a default application environment, automatically creating skeleton code every time a new application component is added, allowing the programmer to design the UI in a graphical way Nonetheless, a lot of details must be managed by hand

APPLICATION RESOURCES Resources: non-code files that are part of an application Images, sounds, videos The application icon The application preferences And more

EMBEDDED APPS (1/2) Mobile apps behave differently from PC applications Only one app is visible at a time to interact with the user. The operating system manages the switch from one application to another The visible app has no windows Apps not interacting with the user are scheduled differently

EMBEDDED APPS (2/2) The operating system may decide to terminate apps not interacting with the user so as to free up resources The lifecycle of apps is optimized for the embedded setting No page file

ANDROID: USER VS. SYSTEM System apps do not use special APIs: they have to go through the same public APIs available to userdeveloped applications Android can be told to make your application replace a standard application. For instance, a userprogrammed keyboard may replace the systemprovided keyboard This open, modular design is unique to Android

ANDROID: ADDING USER APPS Adding applications is done through Android APK (.apk) packages. An APK package is a binary archive containing compiled bytecode, non-compiled resources such as images, and other informations for installing the application Every APK should be digitally signed. However, it is not mandatory that the signature is validated by a CA

Image from developer.android.com THE BUILD PROCESS (1/2)

Image from developer.android.com THE BUILD PROCESS (2/2)

ANDROID: APP TYPES Applications: take over the whole screen. Example: Android s standard web browser Widgets: take a small, fixed portion of the home screen. Example: Android s standard clock. (Note: UI widgets are a different thing!)

APPLICATION ISOLATION Each application runs in its own Linux process with its own user ID. The Linux OS ensures that applications cannot access privileged OS components or hamper one another s memory and data Each application runs in its own copy of the VM. Malfunctions cannot propagate from one application to another Applications communicate through content providers

APP COMPONENTS Activity: a single screen with a user interface Service: performs (in the background) long-running operations (e.g., music playback). No user interface Content provider: encapsulates data that needs to be shared between applications. No user interface Broadcast receiver: responds to system-wide broadcast events (e.g., battery low! ). No user interface Four classes are available, one for each type of component

ABOUT COMPONENTS An application is a mixture of components, each with a distinct lifecycle Any application can ask Android to start another application s component (e.g., the take a shot activity of the camera application) No first component, no application entry point (although a main activity exists)

INTENTS Activities, services and broadcast receivers are activated by intents Intent: asynchronous message that requests an action An intent may request a specific component or just a type of component: in the latter case, it is the system s task to bind the intent to an available component that performs the required action

ACTIVITIES VS. APPLICATIONS Activity: a single, focused thing that the user can do Example: an activity to edit a text-only note Application: contains activities (and other components) Example: a notepad application has an activity to edit a note and another activity to manage a list of notes

ACTIVITY LIFECYCLE (1/2) An activity passes through the following states. Active (aka running): visible, receiving user input Paused: partially visible, not receiving user input (e.g., an alert dialog is above it) Stopped: not visible Destroyed: removed from memory by Android Callback methods allow an activity to perform actions on state transitions

Image from developer.android.com ACTIVITY LIFECYCLE (2/2) State transitions are a consequence of user or system decisions. An activity cannot avoid state transitions: it can only manage them by undertaking appropriate actions

CALLBACK METHODS oncreate() Called when the activity is first created onstart() Called when the activity is becoming visible to the user onresume() Called when the activity will start interacting with the user onpause() Called when the system is about to start resuming a previous activity onstop() Called when the activity is no longer visible to the user onrestart() Called after the activity has been stopped, prior to it being started again ondestroy() Last method to be called before the activity is destroyed

APPLICATION TERMINATION Any activity that is not running may be terminated by Android at any time to free up resources The onstop() and ondestroy() methods are not guaranteed to be called: only onpause() is Morale: save your state every time your activity is paused

ORIENTATION CHANGE Any change between portrait and landscape mode will cause an activity to be paused, then stopped, then destroyed, then a new instance of the activity will be created Once again: save your state every time your activity is paused

Image from developer.android.com BACK STACK Android s Activity Manager arranges activities in a stack (the back stack) according to the order in which they were opened Stopped activity

TASKS Task: set of related activities (i.e., the first activity in the task called all the others) A task is moved to the background as a whole -- and all its activities stopped -- if the user starts a new, unrelated task (e.g., by tapping the Home button and launching a new application) Different instances of the same activity can be present in different tasks

THE MANIFEST FILE The manifest (AndroidManifest.xml) of an application declares the components of the app declares hardware (e.g., specific displays) and software features (e.g., additional API libraries) required by the app lists any user permissions required by the app

THE BUILD.GRADLE FILE Not part of the APK package Contains information about the tools, and the Android version, required to build and run the app android { compilesdkversion 23 buildtoolsversion "23.0.2" } defaultconfig { applicationid "it.unipd.dei.esp1516.hellowithbutton" minsdkversion 15 targetsdkversion 23 versioncode 1 versionname "1.0" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } }

THE FIRST ANDROID APP The application shows a button and a string of text When the button is pressed, the text changes

APPLICATION CLASSES View: base class for user interface components (both widgets and layouts) ViewGroup: base class for layouts and views containers. Extends View Activity: base class for activities LinearLayout: arranges its children in a single row (default) or column. Extends ViewGroup Button, TextView: UI widgets. Extend View

HELLOWITHBUTTON.JAVA (1/2) package it.unipd.dei.esp1516.hellowithbutton; import android.os.bundle; import android.app.activity; import android.view.view; import android.widget.textview; import android.widget.button; import android.widget.linearlayout; public class HelloWithButton extends Activity { /** Called when the activity is first created. */ @Override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // Create the TextView final TextView tv = new TextView(this); tv.settext("press the button, please"); // Create the Button Button bu = new Button(this); bu.settext("press me");

HELLOWITHBUTTON.JAVA (2/2) // Set the action to be performed when the button is pressed bu.setonclicklistener(new View.OnClickListener() { public void onclick(view v) { // Perform action on click tv.settext("good job!"); } }); } } // Create the layout LinearLayout mylayout = new LinearLayout(this); // Add the UI elements to the layout mylayout.addview(bu); mylayout.addview(tv); // Display the layout setcontentview(mylayout);

STRINGS.XML Automatically generated by Android Studio when the app module is created in the project <resources> <string name="app_name">hellowithbutton</string> </resources>

ANDROIDMANIFEST.XML Automatically generated from properties that the programmer specifies via Android Studio <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="it.unipd.dei.esp1516.hellowithbutton"> <application android:allowbackup="false" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme" tools:ignore="googleappindexingwarning"> <activity android:name=".hellowithbutton"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>

APP S BUILD.GRADLE Automatically generated from properties that the programmer specifies via Android Studio apply plugin: 'com.android.application' android { compilesdkversion 23 buildtoolsversion "23.0.2" } defaultconfig { applicationid "it.unipd.dei.esp1516.hellowithbutton" minsdkversion 15 targetsdkversion 23 versioncode 1 versionname "1.0" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } dependencies { compile filetree(dir: 'libs', include: ['*.jar']) testcompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' }

SDK VERSION minsdkversion (integer) Minimum API Level required for the app to run. If not properly set, the app will crash at runtime as soon as it accesses an unsupported API targetsdkversion (integer) API level against whom the app has been tested. The app is still able to run on lower API levels, down to minsdkversion. If not set, it is assumed equal to minsdkversion. maxsdkversion (integer) Maximum API Level on which the app can run. Declaring this attribute is not recommended: new versions of Android are designed to be backward-compatible

<USES-SDK>: EXAMPLE targetsdkversion=8, Android 4.2.2 (API Level 17) targetsdkversion=17, Android 4.2.2 (API Level 17)

API LEVEL The API Level is an integer that identifies the set of APIs supported by a given version of Android Examples: Android 2.2 API Level 8 Android 2.3 API Level 9 Android 2.3.3, 2.3.4,... API Level 10 Android 4.0.3, 4.0.4 API Level 15 To sum things up, each Android release is identified by a Platform Version (e.g., 2.2), an API Level (e.g., 8) and a Version Code (e.g., Froyo )

LAST MODIFIED: MARCH 10, 2016 COPYRIGHT HOLDER: CARLO FANTOZZI (FANTOZZI@DEI.UNIPD.IT) LICENSE: CREATIVE COMMONS ATTRIBUTION SHARE-ALIKE 3.0