1 / 21

INTRO TO ANDROID DEVELOPMENT Development Tools Major Android Application Components Activity and it’s Life Cycle Code

INTRO TO ANDROID DEVELOPMENT Development Tools Major Android Application Components Activity and it’s Life Cycle Code and UI Lists Communication Between Components Further Readings. Android Tools.

tovi
Download Presentation

INTRO TO ANDROID DEVELOPMENT Development Tools Major Android Application Components Activity and it’s Life Cycle Code

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. INTRO TO ANDROID DEVELOPMENT • Development Tools • Major Android Application Components • Activity and it’s Life Cycle • Code and UI • Lists • Communication Between Components • Further Readings

  2. Android Tools • Software Development Kit (SDK): provides you the API libraries and developer tools necessary to build, test, and debug apps for Android. • https://developer.android.com/sdk/index.html • ADT is a plugin for the eclipse IDE that is designed to give you a powerful, integrated environment in which to build Android applications • http://developer.android.com/tools/sdk/eclipse-adt.html • Android Studio: A new Android development environment. “Provides an integrated Android developer tools for development and debugging” • not perfect yet, v0.3.2 • http://developer.android.com/sdk/installing/studio.html

  3. Android Project Elements • Package • Java Source • Resources • layout (XML file) • themes and Styles (XML) • text Elements (XML) • animation and other dynamic graphics (XML) • images, sounds, video, etc. • R.java • Contains all the resources IDs give by the programmer or generated through the sdk. • Android Manifest File (more on this later) • External Libraries

  4. Android Manifest File • Application Descriptor. • Contains the Android version, number of activities, services, content providers (more on this later). • Minimum API level. • Outline of your application for the Android OS. • Can be modified dynamically from code. • Checked by the system before installation. • Contains the hardware and software minimum requirements. • External APIs.

  5. Manifest Attributes and Tags • android:icon:Application icon • android:name:Application name with package name • android:label: Application title • List of components: • <activity>: Activity • <service>: Service • <provider>: Content provider • <receiver>: Broadcast receiver • The Activities, Services andContentProvidersthat are not present in the Manifest, are not visible for the system • HoweverBroadcastReceivers can be defined dynamically from code:registerReceiver()

  6. Major Android Application Components • Activity • Special View with its own UI. • Each activity is independent but they all have important roles in the application. • Other applications can start a specific activity: one of the major features of Android, the communication between components. • For example, when building an application that takes a picture, you don’t have to write the code to access the camera. You send use the default camera Activity, take the picture and return it. • Extend from android.app.Activity • Service • Represent a background task. • Think about them as system-wide threads. They ca run even when the application is not open. • With great power comes great responsibility • Do not have a specific UI • Other components start or bind to it • For example, download process while we are using the application in the foreground. • Extends from android.app.Service

  7. Major Android Application Components • Content Provider • Main goal of ContentProvider is to share a data source with other components. • Data can be stored in different location SQLite database, remote server, SharedPreferences, file. • Other applications can work with the same data by using the same content provider. • Extend from android.content.ContentProvider • Broadcast Receiver • Activated by different system or application events. • For example, screen off, low battery, incoming call, photo ready. • An app can fire their own broadcast events. • They typically do not their own UI, they awake other components or fire up a notification. • Extend from android.content.BroadcastReceiver

  8. Activity and its Life Cycle • There is no main(String[] argv) method! • Android system initiates code in an Activity instance by invoking specific callback functions that depend on the state of the application. • Activity never resides in the created or started state. • All of these functions can be overwridden. • Only overwrite those that will ensure the correct behavior of you application. • Demo!

  9. Communication between UI and Code • View: Basic building block for user interface components. A view occupies a rectangular area on the screen and is responsible for drawing and event handling. • You can have multiple Views displayed in the screen. • In a list, each row is a view. • (Demo) Eclipse provides us a nice interface to design the look of our application. We can simply drag and drop UI components to a View. • It is very important to always give each of our UI elements a unique ID that we will use to reference the element when we code. • The findViewByID(int id)method gives us a way to “grab” the UI element inside the View linked to our Activity (setContentView(View view)) • (Demo)

  10. Lists and their Adapters • Lists are the most common Views used in mobile applications. • Lists present multiple line items in a vertical arrangement. They can be used for data selection as well as drilldown navigation. • To create a list you can either drag and drop a ListView to an Activity or use a ListActivityclass. • ListActivity already contains a ListAdapterand a ListViewcomponent that can be queried by the getListView() function. • public interface ListAdapter: Bridge between a ListViewand the data that backs the list. The ListView can display any data provided that it is wrapped in a ListAdapter. • ArrayAdapter<T>, BaseAdapter, CursorAdapter, HeaderViewListAdapter, ResourceCoursorAdapter, SimpleAdapter, SimpleCursorAdapter, WrapperListAdapter.

  11. Lists and their Adapters • Let’s create a List using ListActivityand and ArrayAdapter<T> • Sometimes lists can hold up to thousands of elements. In these cases you have to optimize our lists, a common hack is to use the View Holder pattern. • http://developer.android.com/training/improving-layouts/smooth-scrolling.html • Recycling views. • Static ViewHolder object

  12. Communication between Activities • Components: • Screens (Activities) • Services • Broadcast Receivers • Content Prviders • Intent: message object. • wraps data of an event which can be: • expected event: Something occurs because an intent was fired. • occurred event: An intent describes somethig that already happened

  13. Communication between Activities • An intent can be fired by any component type. • Always sent to the Android OS, not directly to the recipient. • OS analyses the Intent and chooses the target • Type of the recipient is determined by the method we originally used to fire the Intent. • Intent delivery: • startActivity (Intent intent, Bundle options); • startActivityForResult(Intent intent, intrequestCode); • start or resume an Activity. • startService(Intent intent); • sendBroadcast(Intent intent);

  14. Parts of an Intent • Component name: Fully qualified classname of the target(com.example.applciaton.MainActivity). • Action: String describing the expected or occurred event. • Data: URI or MIME type of the data • Extras: Set of key-value pars that we want to pass to the target • Category: Further criteria about processing component. • Flags: We can override the default behaviour of the starting Activity

  15. startActivityForResult(Intent, requestCode) • What if we want to get something from an Activity that we started? • startActivity() provides no way to return data. • startActivityForResult(Intent, requestCode)! • A single component can begin several activities at the same time, how can we differentiate between each one? • The requestCode differentiates each one!

  16. onActivityResult • A single callback to handle results from all sub-activities: onActivityeResult(intrequestCode, intresultCode, Intent data) {…} • Parameters: • requestCode: The integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from. • resultCode: The integer result code returned by the child activity through its setResult(). • data: in case resultCodeis not enough we can return a whole Intent filled with data. This intent is a set of arbitrary key-value pairs. • No limitation for the amount of data • Key: String • Value: several built-in types, or custom class that implements the Serializableor Parcelableinterface • Lets finish the App!

  17. Further Readings • A great book is Professional Android 4 Application Development: Edition 3 by Reto Meier. Available in Amazon and the Google Play Store • AIT summer study abroad course in Budapest! • Soooo many online resources about Android development THANK YOU!!! :D

  18. Announcements • This Friday is the last day to complete the lab Data Structures II. • Code your final projects incrementally! • Remember the deadline is 12/19 at 5pm. There is NO LATE HANDIN and you must pass the final project in order to pass the class. • Start Early, start now, start yesterday! • Best of Luck and Happy Holidays!

  19. Model-View-Controller • This design pattern is used in Android and iOS • View: Displays UI, represents data and handles interaction. One-to-many relationship with the Controller. • Model: Manages the data. One-to-many relationship with View. • Controller: implements the business logic, handles the interaction of the user with the view and modifies the Model

More Related