1 / 45

COMP 5047 Pervasive Computing Week 6: Smartphones & the Android OS

COMP 5047 Pervasive Computing Week 6: Smartphones & the Android OS. Dr.-Ing. Rainer Wasinger School of Information Technologies. Part 1: Web vs. Native Approaches. The first age of the Web:

barto
Télécharger la présentation

COMP 5047 Pervasive Computing Week 6: Smartphones & the Android OS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP 5047 Pervasive Computing Week 6: Smartphones & the Android OS Dr.-Ing. Rainer Wasinger School of Information Technologies

  2. Part 1: Web vs. Native Approaches • The first age of the Web: • Netscape vs. Microsoft and aggressive extension of HTML, with Microsoft claiming 96% of the browser market by 2002. • The second age of the Web: • Minimal improvements. Introduction of IE6 and a long period of stagnation. • Finally, Safari arrives in 2003 and Firefox in 2004. • The third age of the Web (the present): • Native apps have received most attention. The Apple AppStore solved two large problems: • Trusted device access and • Micro-payments. • … but the web ended up 10 to 20 times bigger in the process and is: • Usable on any device, is inherently searchable, andcomposable with a huge selection of mashup services.

  3. Web vs Native Approaches • The Web: (+): It is open; extensible; currently has some strong supporters (e.g. Apple, Google); is very broadly used by all users. (-): Limited in functionality (w.r.t. access to device-specific features); has slightly different methods for interaction; typically has lesser performance. • Native: (+): Access to underlying device APIs gives flexibility to customise functionality and features; the latest APIs are always available to native first; performance, e.g. w.r.t. direct access to the GPU for games. (-): Sooooooo hard to develop for all mobile operating systems and then maintain the applications as the operating systems continue to evolve. • The Hybrid approach: Utilise web technologies for content and use native approaches only where required.

  4. Smartphone Development

  5. Statistics: Application Store Fronts Android Google Play: 600,000+ applications Apple App Store: 650,000+ applications (as at June.2012)

  6. Part 2: Android OS

  7. Android OS • Android OS: • An open source mobile platform based on the Linux operating system. • Applications are developed using the Java programming language. • Applications run on Dalvik, a custom virtual machine designed for embedded use, which runs on top of a Linux kernel. • Although Android reuses the Java language syntax, it does not provide the full-class libraries and APIs bundled with Java SE or Java ME, using the Harmony Java implementation instead (due to Apache’s license allowing for closed source derived works). • The latest Android OS release for smartphones is 4.1 (API Level 16).

  8. Android OS • Android, License: • Most of the Android code has been released under the Apache License. • Although Android is an open-source product, some development has been continuing under private development branches. • The Apache License allows vendors to add proprietary extensions without submitting those back to the open source community. • Android, Origins: • Developed originally by Google, and later/now by the Open Handset Alliance. • Announced on 05.November.2007, together with the founding of the Open Handset Alliance (OHA). • The OHA: • A consortium of 84 firms (hardware, software, and telecoms) devoted to advancing open standards for mobile devices. • Companies include: Google, HTC, Intel, Motorola, Qualcomm, Texas Instruments, Samsung, LG, T-Mobile.

  9. The Android Stack • The Android platform is a software stack for mobile devices including: • An operatingsystem • Middleware • Key applications

  10. Android OS Features

  11. Android Development • Required software for developing for the Android platform (for Windows XP/Vista/7, Mac OS X 10.5.8 and later, and Linux): • JDK 6 (JRE alone is not sufficient) • Eclipse v3.6.2 Classic or later • http://www.eclipse.org/downloads/ • Android SDK Starter Package v20.0.3 • http://developer.android.com/sdk/installing/index.html • Android Development Tools (ADT) v20.0.3 plugin for Eclipse • http://developer.android.com/tools/sdk/eclipse-adt.html

  12. Android Developer Resources • A good book on Android: The Busy Coder’s Guide to Android Development, by Mark Murphy. • URL: http://commonsware.com/Android/Android_3-4-CC.pdf • Topic: Android 2.3 SDK • Length: 596 pages long • Price: Free (as part of the Four-to-Free model).

  13. Android Developer Resources • URL: http://developer.android.com/about/index.html

  14. Android Developer Resources

  15. Android Developer Resources

  16. Android Developer Resources

  17. Android Developer Resources • API Guides:

  18. Android Developer Resources • Reference:

  19. Some Quick Questions • Who hasn’t used the Eclipse IDE before? • Who isn’t familiar with the Java programming language? • Who isn’t familiar with XML? • Has anyone programmed for Android before? • How many here have smartphones?

  20. Part 3: Eclipse – Using the IDE

  21. Using the Eclipse IDE • Editing code

  22. Using the Eclipse IDE • Designing a GUI

  23. Using the Eclipse IDE • Using the Debugger

  24. Using the Eclipse IDE • LogCat

  25. ***Lab Exercises*** • In this lab, you will learn the following: • Creation of a HelloWorld Android project and the running of the application in the emulator. • Familiarisation with the Eclipse IDE. • Familiarisation with the Android Device Emulator (ADE). • Importing the sample COMP5047 Property Application project into Eclipse, in preparation for the next lab’s GUI design and Activity & Intent coding exercises. • Running other code samples that come with the Android SDK.

  26. Part 4: Example Mobile Applications • Multi-Channel Content Repurposing & Mobile Personalisation Project

  27. Example Mobile Applications Property Organiser (Android) Content Repurposing (Volantis) Museum Tour (iPhone) Dangerous Australians (iPhone) Long-term Career Management (Android) Neighbourhood Networks (Android) Sydney Dashboard (mobile Web) PersonisJ User Modelling across Multiple Mobile Apps (Android)

  28. Part 5: Anatomy of an Android Application • Android applications don’t have a single entry point for everything in the application (i.e. no main() function). Instead, they have essential components that the system can instantiate and run as needed. • This is partly to make the applications more crash-resistant. • There are 4 types of components: • Activities • Services • Content providers • Broadcast receivers • We will focus on the Activity component.

  29. Android Components • Services: • Services run in the background to perform long-running operations. They do not provide a visual user interface. • E.g. a service might play background music, or might fetch data over the network without blocking user interaction with an activity. • Content providers: • Content providers make a specific set of an application’s data available to other applications. Such data can for example be stored in the file system, or in an SQLite database. • E.g. the Android system uses a content provider to manage the user’s contact information. • Broadcast receivers: • These are components that do nothing but receive and react to system-wide broadcast announcements. • E.g. an announcement might be that the time zone has changed, that the battery is low, or that a picture has been taken.

  30. Android Components (cont.) • Activities: • Activities represent the building block of the user interface. • An activity presents a visual user interface for one focused endeavour that the user can undertake. • E.g. an activity might present a list of contacts to send messages to, while other activities might deal with the writing of messages, the viewing of old messages, and the changing of settings. • Each activity is independent of the others, and each one is implemented as a subclass of the Activity base class.

  31. Tasks and the Activity Stack • A ‘task’ is what the user experiences as an ‘application’. It is a group of related activities, arranged in a stack. • The root activity in the stack is the one that began the task, e.g. the activity the user selected in the application launcher. • One activity can start another activity. When this happens, the new activity is pushed onto the stack and it becomes the running activity. • When the user presses the back key, the current activity is popped from the stack, and the previous one resumes as the running activity. • Starting a task: An activity is set up as the entry point for a task by giving it an intent filter with “android.intent.action.MAIN” as the specified action and “android.intent.category.LAUNCHER” as the specified category.

  32. The Lifecycle of an Activity • The main lifecycle states: • Resumed: The activity is in the foreground of the screen and users can interact with it. Also referred to as the “running” state. • Paused: The activity is partially obscured by another activity and will not receive user input during this time and cannot execute any code. • Stopped: The activity is completely hidden by other activities that have been launched; it is considered to be in the background. While stopped, the activity instance and state information is retained, but it cannot execute any code.

  33. The Lifecycle of an Activity (cont.) • onCreate() and onDestroy(): • The entire lifetime of an Activity happens between the first call to onCreate() through to a single final call to onDestroy(). • An Activity does all of its initial setup in onCreate() and releases all remaining resources by the time onDestroy() is called. • onStart(), onRestart(), and onStop(): • The visible lifetime of an Activity happens between a call to onStart() until a corresponding call to onStop(). • onStart() is called when an activity is first launched. • onRestart() is called when an activity is brought back to the foreground after having been hidden. • onStop() is called when the activity is about to be stopped.

  34. The AndroidManifest.xml File • Before Android can start an application, it must learn that the component exists. Applications declare their components in a manifest file that is bundled into the Android package, i.e. the .apk file that holds the application’s code, files, and resources. • The manifest is a structured XML file and is always named AndroidManifest.xml for all applications. • In addition to declaring the application’s components, it also identifies any permissions the application expects to be granted and the minimum level of the Android API that the application requires.

  35. Intents • While one Activity will be special in that it is used to start an application, the other activities also need to be reached. This is done through the use of asynchronous messages called Intents. • An Intent is an object that holds the content of a message. Intents can be very specific (e.g. requesting a specific Activity to be launched) or can be more generic (e.g. when multiple criteria is needed for selecting an Activity to launch). • Activities are launched by passing an Intent object to the Context.startActivity() method.

  36. Intent Filters • An Intent object can explicitly name a target component. If it does, Android finds that component and activates it. If a target is not explicitly named, Android must locate the best component to respond to the intent. • A component can have any number of intent filters, each one declaring a different set of capabilities. • If a component doesn’t have any filters, it can be activated only by intents that explicitly name the component as the target.

  37. Designing the User Interface • User interfaces are built using View and ViewGroup objects. • The View class serves as the base for subclasses called “widgets”, which offer fully implemented UI objects, like text fields and buttons. • The ViewGroup class serves as the base for subclasses called “layouts”, which offer different kinds of layout architecture, like linear, tabular, and relative. • To attach a view hierarchy tree to the screen for rendering, an Activity must call the setContentView() method and pass a reference to the root nodeobject. View Hierarchy

  38. Designing the User Interface (cont.) • The most common way to define a layout and express the view hierarchy is with an XML layout file. • Each element in XML is either a View or ViewGroup object. • View objects are the leaves in the tree. • ViewGroup objects are the branches in the tree. • Combining different Views in a nested XML structure is the basis for GUI creation.

  39. Part 6: The Code

  40. Notepad Example - The Eclipse IDE

  41. Notepadv3 Example – The Manifest <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.demo.notepad3"> <application android:icon="@drawable/icon"> <activity android:name=".Notepadv3" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".NoteEdit"/> </application> </manifest>

  42. Notepadv3 Example – An Activity Class public class Notepadv3 extends ListActivity { ... /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.notes_list); mDbHelper = new NotesDbAdapter(this); mDbHelper.open(); fillData(); registerForContextMenu(getListView()); } //onCreate ...

  43. Notepadv3 Example – An Intent @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Intent i = new Intent(this, NoteEdit.class); i.putExtra(NotesDbAdapter.KEY_ROWID, id); startActivityForResult(i, ACTIVITY_EDIT); }

  44. Notepadv3 Example – notes_list.xml GUI <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ListView android:id="@+id/android:list" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/android:empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="No Notes!"/> </LinearLayout>

  45. COMP5047 Property App Week 6 Lab Task • Screen shots

More Related