500 likes | 702 Views
Android Development . Kelly McBean. Development Environment Overview. Eclipse Standard IDE for Developing Android Applications Install: Java (JDK) – Since Eclipse Runs on top of Java Eclipse Standard Using Eclipse “Install Software” Developer Tools (Plugins) Android SDK
E N D
Android Development Kelly McBean
Development EnvironmentOverview • Eclipse • Standard IDE for Developing Android Applications • Install: • Java (JDK) – Since Eclipse Runs on top of Java • Eclipse Standard • Using Eclipse “Install Software” • Developer Tools (Plugins) • Android SDK • Android APIs
http://java.com Testing for Java If you get the Congratulations message, skip to Installing Eclipse…else continue with the Java Install
Installing Java • Install Documentation: • http://developer.android.com/sdk/installing.html • Java Platform (JDK) • http://www.oracle.com/technetwork/java/javase/downloads/index.html
Install latest version * for appropriate OS * At this time 7u25 is the latest Installing Java
Downloads: • http://www.eclipse.org/downloads • Install: • Save file to a temp folder • Open Zip file and copy the eclipse to root (c:\) • Run eclipse from c:\eclipse\eclipse.exe • Accept the default workspace Installing Eclipse
From Inside Eclipse: • Menu: Help > Install New Software… • Work with: http://dl.google/android/eclipse Installing Plug-in After Accepting License Agreement Eclipse will reboot and continue with installing SDK
Note the Target Location Installing SDK Accept All And Wait…
The Android APIs are the Android platforms (i.e. 2.2, 4.1, etc.) By Default, only One API is installed To check on Installed Android APIs: Windows > Preferences Android Tab Installing API Optional: Menu: Windows > Android SDK Manager Choose Additional APIs to Install
The AVD is an emulator instance that enables you to model an actual device • APIs are available to emulate many of the most popular Android devices • While tethering a device through a USB connection is possible, AVDs are invaluable for testing applications Virtual Devices (AVD)
The AVD is an emulator instance that enables you to model an actual device Creating a Virtual Device Menu: Windows > AVD Manager You will need one for each API you want to test…
Update Environment Path My Computer. Properties. Advanced Add “C:\android-sdks\tools; C:\android-sdks\platform-tools” to … Environment . System . Path Optional?
Eclipse Development Environment for Android The Eclipse Development Environment should be ready to go…
Creating Android Application Application Name is shown in Play Store Project Name must be unique within Android Workspace Package Name is a Unique Identifier for the Application
Anatomy of an Android Application • src – Contains the Java source files for the project • gen – Contains the R.java file, a compiler-generated file that references all the project resources • res – All the project resources. Also contains subfolders to support devices with different size screen resolutions and densities • values – Contains string constants for the application • AndroidManifest – The manifest for the Android application includes the Intents for the Activities and any permissions needed by the application
Activities and intents • An Activity is a window that contains the user interface • An application can have zero or more activities • In Android, you navigate between Activities through what is known as an intent • Intents enable different activities from different applications to work together
Dialog windows are used to display information and sometimes to get confirmation from the user • Common Dialog Windows consist of: • Toast • A message that pops up on the bottom of the user screen for a short period of time • Alert Dialog Window • Displays choices to the user and waits for a response • Progress Dialog Window • Useful for displaying the progress of a process Dialog Windows
A toast provides simple feedback in a small popup • Toasts take 3 parameters • Application Context • Text Message • Duration Toast Dialog OR
Alert Dialog gets a confirmation from the user Code to handle the following events Positive: Typically “OK” Negative: Typically “Cancel” MultiChoice: When the user selects from a list Alert Dialog
In Android, you navigate between activities through what is known as an intent • Results can be returned from an Intent • Data can also be passed using Intent Object • Built-in applications can be called using Intents • Web Browser • Phone Dialer • Contacts • Map • Etc. INtents
A notification is a message displayed to the user outside of the applications UI To see the details of the notification, the user opens the notification drawer Notifications • This is the old way of calling notifications but still works…
Activity to receive the notification is just a single TextView Notifications
Installing and Configuring the IDE • Java (JDK) • Eclipse • Plug-Ins • SDKs • APIs • The UI screen for Android Applications are called Activities • Intents are used to link Activities • There are built-In Intents (Browser, Contacts, Etc.) • Dialog Windows • Toasts • Alerts • Progress • Notifications Recap
An Activity is a window that contains the user interface (Views and ViewGroups) • Views consist of • TextViews (labels) • TextEdits (text boxs) • Radio Buttons • Check Boxes • Date Pickers • Time Pickers • Etc. User interface (Activities)
ViewGroups are layouts used to arrange Views into proper location on the screen • Android supports the following ViewGroups • Linear Layouts • Absolute Layout • Table Layout • Relative Layout • Frame Layout • Scroll View • ViewGroups can be nested User interface (Activities)
The Linear Layout Stacks Views on top of each other • Orientation can be Vertical (default) or Horizontal Viewgroups (Linear Layout) Linear Layout View Linear Layout View View View View View
The Relative Layout arranges Views in relation to the parent or other Views Viewgroups (Relative Layout) Relative Layout View View View View View View View
The ScrollView enables users to scroll through a list of Views that occupy more space than the physical display • The ScrollView can only have one child, typically a Linear Layout Viewgroups (ScrollView) ScrollView Linear Layout View View View View View
A preferable alternate to anchoring is to create custom screens based on orientation • To support Landscape mode, create a new folder in the res folder named layout-land Custom Orientations Screens • Layouts contained in the layout folder defines the UI for portrait mode • Layouts contained in the layout-land folder defines the UI for landscape mode
Changing screen orientation destroys the Activity and re-creates it • Current state of the Activity is lost • When an Activity is killed, it’ll fire the onPause and onSaveInstanceState events • You can implement the onPause event to save state information to database, internal or external storage • Or • Implement the onSaveInstanceState event and save the state using Bundle object • After the activity is re-recreated retrieve and reset the state in the onRestoreInstanceState event Persisting State Information
Persisting State Information • Flow: • Orientation Changes • Activity is Killed • Activity is re-created • State information “McBean” is lost
These are the major events triggered during the life cycle of an Activity • Additionally • onRestoreInstanceState occurs after onStart • onSaveInstanceState occurs after onPause Activity Life cycle
Registering Events for Views • Views can fire events when user interacts with them • The appropriate events need to be explicitly registered • Events can be registered using an inner class or an anonymous class
Using the AnchorView as an example • The buttons are linked to the UI buttons using findViewById • The setOnClickListener gives the buttons “ears” to listen for the click event to be triggered by the user • btn1…btn4 call an anonymous class btnListener • Btn5 calls an inner class Registering Events for Views
Views commonly used are: TextView – Display Information EditText – Allows user to key in Information CheckBox – Turn on and off RadioButtons – Select one in a list ToggleButton – Turn on and off Basic Views
The ListView displays a long list of items in an Activity • No UI Layout Required • Presentation is dictated by the second parameter of the setListAdapter Simple LIST View
Colleges array was moved to strings.xml file and now called as a resource Custom LIST View
Similar to the ListView except is used when other Views will be displayed on the UI Spinner View