Unlocking Android Chapter 4.  Understanding activities and views  Exploring the Activity lifecycle  Working with resources  Defining the AndroidManifest.xml.

Slides:



Advertisements
Similar presentations
Google Android Introduction to Mobile Computing. Android is part of the build a better phone process Open Handset Alliance produces Android Comprises.
Advertisements

Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an.
CE881: Mobile and Social Application Programming Simon M. Lucas Menus and Dialogs.
Pages and boxes Building quick user interfaces. learning objectives o Build a quick UI with pages and boxes o understand how pages and boxes work o click.
Android 02: Activities David Meredith
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
 User Interface - Raeha Sandalwala.  Introduction to UI  Layouts  UI Controls  Menus and ‘Toasts’  Notifications  Other interesting UIs ◦ ListView.
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Filip Debelić What is it? Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google Android,
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
By: Jeremy Smith.  Introduction  Droid Draw  Add XML file  Layouts  LinearLayout  RelativeLayout  Objects  Notifications  Toast  Status Bar.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Android Development (Basics)
Android: Layouts David Meredith
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Better reference the original webpage :
Introducing the Sudoku Example
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
CS5103 Software Engineering Lecture 08 Android Development II.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
ANDROID UI – FRAGMENTS. Fragment  An activity is a container for views  When you have a larger screen device than a phone –like a tablet it can look.
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 2: Simplify! The Android User Interface
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 5: Investigate! Android Lists, Arrays,
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
CS378 - Mobile Computing Intents.
Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Overview of Android Application Development
SpotOn Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Android Boot Camp for Developers Using Java, 3E
User Interfaces: Part 1 (View Groups and Layouts).
Android – Fragments L. Grewe.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Field Trip #32 Digital Alarm Clock By Keith Lynn.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Creating multiple views Introduction to intents Passing data to.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Recap of Part 1 Terminology Windows FormsAndroidMVP FormActivityView? ControlViewView? ?ServiceModel? Activities Views / ViewGroups Intents Services.
1 Android Development Lean and mean introduction Based on a presentation by Mihail L. Sichitiu.
CS378 - Mobile Computing User Interface Basics. User Interface Elements View – Control – ViewGroup Layout Widget (Compound Control) Many pre built Views.
Building User Interfaces Basic Applications
CHAPTER 4 Fragments ActionBar Menus. Explore how to build applications that use an ActionBar and Fragments Understand the Fragment lifecycle Learn to.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
Android Fundamentals. What is Android Software stack for mobile devices Software stack for mobile devices SDK provides tools and APIs to develop apps.
INTRODUCTION TO ANDROID. Slide 2 Introduction I take a top-down approach to describing an application’s anatomy.
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Putting together the AndroidManifest.xml file Creating multiple.
Editing a Twitter search. Viewing search results in a browser.
Why Learn Android? Largest installation base of any operating system Over 20,000 Android devices exist Businesses will likely move more to device-based.
Section 10.1 Define scripting
Chapter 2: Simplify! The Android User Interface
several communicating screens
MAD.
Activities and Intents
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
ANDROID UI – FRAGMENTS UNIT II.
CS5103 Software Engineering
Building User Interfaces Basic Applications
HNDIT2417 Mobile Application Development
Programming Mobile Applications with Android
Introduction to Android
Mobile Programmming Dr. Mohsin Ali Memon.
Presentation transcript:

Unlocking Android Chapter 4

 Understanding activities and views  Exploring the Activity lifecycle  Working with resources  Defining the AndroidManifest.xml

 Views and other Android components ◦ compiled into a binary form R.java ◦ available to applications as resources ◦ make use of strings, colors, styles, and graphics  R.java class ◦ automatically generated ◦ provides a reference to individual resources ◦ is the bridge between binary references and source. ◦ to grab a string or a color and add it to a View.  AndroidManifest. Xml ◦ where your application begins ◦ what its permissions are ◦ Activities (services and receivers ) it includes

 Requirements ◦ Allows the user to search for restaurant reviews based on location and cuisine. ◦ Allow the user to call, visit the website of, or map directions to a selected restaurant.  Need three basic screens to begin with: ◦ A criteria screen where a user enters parameters to search for restaurant reviews ◦ A list-of-reviews screen that shows paged results that match the specified criteria ◦ A detail page that shows the review details for a selected review item  A screen =an Activity

 it gives our application a context, ◦ because Activity itself extends android.app.ApplicationContext;  it brings the Android lifecycle methods into play;  it gives the framework a hook to start and run your application; and  it provides a container into which View elements can be placed.

 Needs three Views ◦ because an Activity represents an interaction with the user, it needs to provide components on the screen. ◦ location, cuisine, and grabReviews  Location ◦ is a type of View ◦ known as an EditText  cuisine ◦ is a fancy select list component, ◦ known in Android terms as a Spinner, and  grabReviews ◦ is a Button.

 This is one of a series of important lifecycle methods the Activity class provides.  Every Activity will override onCreate(), ◦ component initialization steps are invoked, ◦ not every Activity will need to override other lifecycle methods.

 setContentView() ◦ normally associate an XML layout file ◦ you do not have to use an XML file at all;  you can instead define all of your layout and View configuration in code, as Java objects. ◦ it is often easier, and better practice use an XML layout resource  decoupling,  each xml layout file for each Activity.  An XML layout file ◦ defines View objects,  are laid out in a tree,  can then be set into the Activity for use.

 Dynamic Views ◦ Can bind to data, ◦ can be referenced in code ◦ cast to their respective subtypes  Static Views ◦ don’t need to interact with or update at runtime  like labels, ◦ do not need to be referenced in code

 “Adapter” concept ◦ link views that contain collections ( AdapterView ) with data. ◦ a collection handler that returns each item in the collection as a View.  An Adapter ◦ is an interface ◦ a bridge between an AdapterView and the underlying data for that view.AdapterView ◦ provides access to the data items ◦ making a View for each item in the data setView ◦ many basic adapters:  ListAdapter, ArrayAdapter, GalleryAdapter, CursorAdapter, And more.  can create your own Adapter  An AdapterView  a subclass of view and viewgroup  an abstract class  is a view whose children are determined by an AdapterAdapter ◦ commonly used subclasses of AdapterView ◦ ListView, GridView, Spinner, and Gallery ListViewGridViewSpinnerGallery

 using an ArrayAdapter that is populated with ◦ Context (this), ◦ a View element defined in an XML resource file  used for the element shown in the Spinner before it is selected; ◦ an array representing the data  After the spinner selected ◦ Set a different View (R.layout.spinner_view_dropdown) for the drop- down

 Once our Adapter and its View elements are defined, we set it into the Spinner object  Handle event ◦ OnClickListener with our Button, in order to respond when the button is clicked

 After the onCreate() method is complete, with the binding of data to our Spinner views, we have menu buttons and associated actions. ◦ different than on-screen Button views  Menu Button vs on-screen Button ◦ is invoked by pressing the Menu button on the device and tapping a selection (button and a tap) ◦ an on-screen button (single tap)

 Menu class add() method to create a single MenuItem element B. ◦ passing a group ID, ◦ An ID, ◦ an order, and ◦ a text resource reference to create the menu item.  Assigning to the menu item an icon with the setIcon method. ◦ The text and the image are externalized from the code, again using Android’s concept of resources.  The MenuItem ◦ duplicates the on-screen Button with the same label for the “Get reviews” purpose.

onMenuItemSelected() event method C, where we parse the ID of the multiple possible menu items with a case/switch statement.

HandleGetReviews puts the user’s selection state in the Application object sets up to call the next screen. used in multiple places, 1.from our on-screen Button 2.from our MenuItem.

 Used internally by Android for many purposes,  Can be extended, ◦ RestaurantFinderApplication ◦ includes a few member variables in JavaBean style  Store global state information ◦ Can be retrieve later  One way to pass objects back and forth between activities; ◦ You can also use public static members and Intent extras with Bundle objects. ◦ You can use the provided SQLite database, or ◦ You can implement your own ContentProvider and store data there.

asking another Activity to respond to the user’s selection of a menu item by calling startActivity (Intent intent)

validate() Called before we allow the next Activity to be invoked, display a pop-up-style alert dialog to the user if the location has not been specified. OnClickListener() button can be made to respond to a click event AlertDialog.BuilderAlertDialog.Builder(Context context)Context Constructor using a context for this builder and the AlertDialog it creates. AlertDialog

 Every process running on the Android platform  is placed on a stack.  Android can’t keep every process running forever ◦ system resources are finite.  How to use the limit resources? ◦ When you use an Activity in the foreground, the system process that hosts that Activity is placed at the top of the stack, ◦ previous process (the one hosting whatever Activity was previously in the foreground) is moved down one notch

 Foreground activity ◦ at the top of the screen that the user is currently interacting with  Visible activity ◦ an activity that is visible to the user but not in the foreground, ◦ such as one sitting behind a foreground dialog  Background activity ◦ Any process hosting a background Activity is next in line.  Empty process ◦ Any process not hosting any Activity (or Service or BroadcastReceiver)is last in line.

Related to layout

 Layout is defined in terms of ◦ ViewGroup ◦ LayoutParams  ViewGroup ◦ is a container  is a View that contains other views (has children)  Child View elements must fit into the layout specified by their parents.  a child View has to lay itself out based on its parents’ LayoutParams  a child View specify a different layout for its own children  LayoutParams ◦ public static class- ViewGroup.LayoutParams ◦ used by views to tell their parents how they want to be laid out ◦ dimensions —width and height ◦ relative or absolute placement ◦ Margins

 Allow other components to attach and listen for events. ◦ View class methods:  onFocusChanged(), onSizeChanged(), onLayout(), onTouchEvent()  Similarly, other items ◦ Activity lifecycle methods  onCreate(), onFreeze()

This maps to an XML layout file at src/res/layout/review_detail.xml

 Views and layout are defined in XML ◦ rather than in Java code ◦ as resources  Benefits ◦ easier to work with ◦ decoupled from the code ◦ Reusable  Resource files ◦ are placed in the res/layout source directory ◦ many XML files allowed ◦ the root of these XML files is  subclasses ofViewGroup  RelativeLayout, LinearLayout, FrameLayout ◦ body of XML  represent the view/layout tree.

layout_[attribute] Android: padding = setPadding() android:

 Android requires a manifest file for every application  Is placed in the root directory of the project source  Describes ◦ application context ◦ supported activities ◦ services ◦ intent receivers ◦ content providers ◦ permissions

To inform the system which implicit intents they can handle Each filter describes a capability of the component, a set of intents that the component is willing to receive.