• No results found

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

N/A
N/A
Protected

Academic year: 2021

Share "ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android"

Copied!
6
0
0

Loading.... (view fulltext now)

Full text

(1)

ECWM511 MOBILE APPLICATION DEVELOPMENT

Lecture 1: Introduction to Android

Dr Dimitris C. Dracopoulos

Why Android?

■ A truly open, free development platform based on Linux and open source

■ A component-based architecture

■ Tons of built-in services out of the box (GPS, SQL, browser and map views)

■ Automatic management of the application life cycle

■ High-quality graphics and sound ◆ 3D-accelerated OpenGL graphics

◆ various codecs for audio and video formats built-in

■ Portability across a wide range of current and future hardware (apps in Java)

2 / 23

(2)

Native Libraries

■ Surface Manager: drawing commands go into off-screen bitmaps that are then combined with other bitmaps to form the display the user sees.

■ 2D and 3D graphics: Two- and three-dimensional elements can be combined in a single user interface with Android. The library will use 3D hardware if the device has it or a fast software renderer if it doesn’t.

■ Media codecs: Android can play video and record and play back audio in a variety of formats including AAC, AVC (H.264), H.263, MP3, and MPEG-4.

■ SQL database: Android includes the lightweight SQLite database engine, the same database used in Firefox and the Apple iPhone.

■ Browser engine: For the fast display of HTML content, Android uses the Chromium library. Same engine used in the Google Chrome browser and close to Apple’s Safari browser and the Apple iPhone.

4 / 23

Android Runtime

■ Core Java Libraries (different than Java SE but there is a substantial amount of overlap)

■ Dalvik: Java virtual machine optimized for low memory requirements

◆ runs .dex files, which are converted at compile time from standard .class and .jar files. ◆ .dex files are more compact and efficient than class files, an important consideration for the

limited memory and battery-powered devices that Android targets.

■ ART (Android 5.0 and newer): When an application is installed in a device, ART compiles it into machine code.

5 / 23

Application Framework

Provides the high-level building blocks you will use to create your applications.

■ Activity Manager

◆ Controls the life cycle of applications

◆ Maintains a common backstack for user navigation

■ Content providers: Objects encapsulate data that needs to be shared between applications (e.g. contacts)

■ Resource manager: Resources are anything that goes with your program that is not code

■ Location manager: An Android phone always knows where it is

■ Notification manager: Events such as arriving messages, appointments, proximity alerts, alien invasions, and more can be presented to the user

6 / 23

Applications and Widgets End users will see only these programs.

■ Applications: Programs that can take over the whole screen and interact with the user

■ Widgets: Operate only in a small rectangle of the Home screen application

Android phones preprepackaged with a number of standard system applications, including:

■ Phone dialer

■ Email

■ Contacts

■ Web browser

■ Google Play Store

(3)

It’s Alive!

Standard Linux or Windows desktop, you can have many applications running and visible at once in different windows. One of the windows has keyboard focus, but otherwise all the programs are equal. Android doesnt work that way:

■ There is one foreground application, which typically takes over the whole display except for the status line.

■ When the user turns on their phone, the first application they see is the Home application.

■ When the user runs an application, Android starts it and brings it to the foreground. From that application, the user might invoke another application, or another screen in the same application, and then another and another.

■ All these programs and screens are recorded on the application stack by the system’s Activity Manager.

■ At any time, the user can press the Back button to return to the previous screen on the stack. 8 / 23

Process != Application

Each user interface screen is represented by an Activity class. Each activity has its own life cycle.

■ An application is one or more activities plus a Linux process to contain them.

■ In Android, an application can be alive even if its process has been killed (the activity life cycle is not tied to the process life cycle).

■ Processes are just disposable containers for activities.

9 / 23

Building Blocks of an Application

■ Activities: A user interface screen. Applications can define one or more activities to handle different phases of the program.Each activity is responsible for saving its own state so that it can be restored later as part of the application life cycle. Activities extend the Context class, so you can use them to get global information about your application.

■ Fragments: Components of an activity. They can be visible but they don’t have to be. Using fragments allows you to more easily adapt to different-sized scre ens.

10 / 23 An example of Fragments Activity A Fragment A Activity B Fragment B selecting an item starts Activity B contains contains Handset Tablet Activity A

contains Fragments A and Fragment B selecting an item

updates Frgment B

(4)

Building Blocks of an Application (cont’d)

■ Views: A view is the smallest level of the user interface. Views are contained directly by activities or by fragments inside activities.

They can be created by Java code, or preferably, by XML layouts.

12 / 23

Building Blocks of an Application (cont’d)

■ Intents: A mechanism for describing a specific action, such as pick a photo, or phone home. Example: there is an intent for send an email.If youre writing a new email application, you can register an activity to handle that intent and replace the standard mail program.The next time somebody tries to send an email, theyll get the option to use your program instead of the standard one.

■ Services: A task that runs in the background without the users direct interaction, similar to a Unix daemon.

Example: a music player. The music may be started by an activity, but you want it to keep playing even when the user has moved on to a different program.

13 / 23

Building Blocks of an Application (cont’d)

■ Content Providers: a set of data wrapped up in a custom API to read and write it. This is the best way to share global data between applications. Example: Google provides a content provider for contacts. All the information there - names, addresses, phone numbers, and so forth, can be shared by any application that wants to use it.

14 / 23

Life cycle of an Android activity

(5)

Life cycle of an Android activity

■ onCreate(Bundle): This is called when the activity first starts up.

■ onStart(): This indicates the activity is about to be displayed to the user.

■ onResume(): This is called when your activity can start interacting with the user. This is a good place to start animations and music.

■ onPause(): This runs when the activity is about to go into the background, usually because another activity has been launched in front of it. This is where you should save your programs persistent state. Things like stopping animation, music should be done here as well. Avoid CPU intensive tasks in here, such as a database writing.

■ onStop(): This is called when your activity is no longer visible to the user and it wont be needed for a while. If memory is tight, onStop( ) may never be called (the system may simply terminate your process).

16 / 23

Life cycle of an Android activity (cont’d)

■ onRestart(): If this method is called, it indicates your activity is being redisplayed to the user from a stopped state.

■ onDestroy(): This is called right before your activity is destroyed.

■ onSaveInstanceState(Bundle): Android will call this method to allow the activity to save per-instance state, such as a cursor position within a text field. Usually you wont need to override it because the default implementation saves the state for all your user interface controls (Views) automatically.

■ onRestoreInstanceState(Bundle): This is called when the activity is being reinitialized from a state previously saved by the onSave- InstanceState( ) method. The default implementation restores the state of your user interface.

17 / 23

Lifecycle of a Fragment Similar to that of an Activity.

The following lifecycle methods have to be implemented at least:

■ onCreate(): Called when creating the fragment. Initialize essential components of the fragment that you want to retain when the fragment is paused or stopped, then resumed.

■ onCreateView(): Called it is time for the fragment to draw its UI.

■ onPause(): First indication that the user is leaving the fragment (though it does not always mean the fragment is being destroyed). Commit any changes that should be persisted beyond the current user session (because the user might not come back).

18 / 23

(6)

Using Resources

A resource is a localized text string, bitmap, or other small piece of noncode information that your program needs. At build time all your resources get compiled into your application.

■ You create and store your resources in the res directory inside your project.

■ The Android resource compiler (aapt) processes resources according to which subfolder they are in and the format of the file.

For example:

◆ PNG and JPG format bitmaps should go in a directory starting with res/drawable ◆ XML files that describe screen layouts should go in a directory starting with res/layout

20 / 23

Safety and Security

■ Every application runs in its own Linux process.

■ The hardware forbids one process from accessing another process’s memory.

■ Every application is assigned a specific user ID. Any files it creates cannot be read or written by other applications.

In addition:

■ Access to certain critical operations are restricted, and you must specifically ask for permission to use them in a file named Android-Manifest.xml.

■ When the application is installed, the Package Manager either grants or doesn’t grant the permissions based on certificates and, if necessary, user prompts.

21 / 23

Safety and Security (cont’d) Some of the most common permissions are:

■ INTERNET: Access the Internet.

■ READ CONTACTS: Read (but dont write) the user’s contacts data.

■ WRITE CONTACTS: Write (but dont read) the user’s contacts data.

■ RECEIVE SMS: Monitor incoming SMS (text) messages.

■ ACCESS COARSE LOCATION: Use a coarse location provider such as cell towers or wifi.

■ ACCESS FINE LOCATION: Use a more accurate location provider such as GPS.

For example, to monitor incoming SMS messages, you would specify this in the manifest file: 22 / 23

Safety and Security (cont’d)

<manifest xmlns:android="http://schemas.android.com/ apk/res/android" package="com.google.android.app.myapp" > <uses-permission android:name= "android.permission.RECEIVE_SMS" /> </manifest> 23 / 23

References

Related documents

 Appeal of smart home product and solution categories  General attitudes to purchasing products and solutions  Current use/future interest in specific smart home products.

• Majors Course equivalence form – signed by Columbia instructor teaching similar class; signed by SEAS major department adviser • Study Abroad registration – Office of

Recommendation 10: Following the publication of the Scottish Medicines Consortium review and the Individual Patient Treatment Requests review, the Scottish Government must implement

and LCP olecranon plate Good Fair Fair Fair Excellent Excellent Excellent Good Good Poor Good LOM Ulnar nerve Sx Heterotophic ossification LOM, ulnar nerve Sx Ulnar nerve Sx

This project consists of four studies, and generates knowledge relevant for the research priorities of the EuroQol group. This project is about understanding

Invitations to participate in the consultation were sent out through existing global and regional networks with the aim of bringing together a community of key partners

Table 8 – Number Ni of allowed axle group passages and aggressiveness Ai = Nref/Ni (Nref for standard single axle) for each axle group (A to E) of the vehicles on the pavements (tb:

The DSRIP demonstration is an opportunity to support providers in a way that is not traditionally allowed through Medicaid funds. To this end, DMAS intends on maintaining the