CE881: Mobile and Social Application Programming Simon M. Lucas Quiz, Walkthrough, Exercise, Lifecycles, Intents.

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

Programming with Android: Activities and Intents
Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from.
Molecular Biomedical Informatics Web Programming 1.
Threads, Surface Views and Real-Time Games. Background Most of the Android apps we’ve covered so far have been single threaded – And Event driven – An.
CE881: Mobile and Social Application Programming Simon M. Lucas Menus and Dialogs.
CE881: Mobile and Social Application Programming Simon M. Lucas Layouts.
Android basics. About Android Linux based operating system Open source Designed for handheld devices Developed by Android Inc. Google (2005) Open Handset.
Cosc 5/4730 Android: “Dynamic” data.. Saving Dynamic data. While there are a lot of ways to save data – Via the filesystem, database, etc. You can also.
Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Informatica – Scienza e Ingegneria Università di Bologna.
Programming with Android: Activities
Unlocking Android Chapter 4.  Understanding activities and views  Exploring the Activity lifecycle  Working with resources  Defining the AndroidManifest.xml.
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.
The Android Activity Lifecycle. Slide 2 Introduction Working with the Android logging system Rotation and multiple layouts Understanding the Android activity.
The Activity Class 1.  One application component type  Provides a visual interface for a single screen  Typically supports one thing a user can do,
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.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Programming with Android: Android Fragments Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 9: Customize! Navigating with a Master/Detail.
PROG Mobile Java Application Development PROG Mobile Java Application Development Event Handling Creating Menus.
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
© 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.
Software Architecture of Android Yaodong Bi, Ph.D. Department of Computing Sciences University of Scranton.
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,
DUE Hello World on the Android Platform.
CS378 - Mobile Computing Intents.
Copyright© Jeffrey Jongko, Ateneo de Manila University Of Activities, Intents and Applications.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
Understand applications and their components activity service broadcast receiver content provider intent AndroidManifest.xml.
Android – Fragments L. Grewe.
Networking: Part 1 (Web Content). Networking with Android Android provides A full-featured web browser based on Chromium, the open source browser engine.
© 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.
ANDROID L. Grewe Components  Java Standard Development Kit (JDK) (download) (latest version)  AndroidStudio.
Cosc 4730 Android Fragments. Fragments You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own.
Noname. Conceptual Parts States of Activities Active Pause Stop Inactive.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
Introducing Intents Intents Bind application components and navigate between them Transform device into collection of interconnected systems Creating a.
Android Application Lifecycle and Menus
Activities and Intents Chapter 3 1. Objectives Explore an activity’s lifecycle Learn about saving and restoring an activity Understand intents and how.
CHAPTER 4 Fragments ActionBar Menus. Explore how to build applications that use an ActionBar and Fragments Understand the Fragment lifecycle Learn to.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
The Flag Quiz app tests your ability to correctly identify 10 flags from various countries and territories.
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.
Menus. Menus are a common user interface component in many types of applications. The options menu is the primary collection of menu items for an activity.
Activities and Intents
The Android Activity Lifecycle
ANDROID UI – FRAGMENTS UNIT II.
Activities and Intents
Activities and Intents
HNDIT2417 Mobile Application Development
Activities and Intents
Objects First with Java
It is used to Start an Activity Start a Service Deliver a Broadcast
SE4S701 Mobile Application Development
Activities and Fragments
Android Development Tools
Activities, Fragments, and Intents
Presentation transcript:

CE881: Mobile and Social Application Programming Simon M. Lucas Quiz, Walkthrough, Exercise, Lifecycles, Intents

Activity State Transitions and Methods

Tips for State Management Save any important information frequently or immediately – Mobile device: the battery could die any time! Override onPause or onStop to save useful non-critical state (onDestroy is a bit too last- minute for most things) When overriding onCreate, check to see whether savedInstanceState is non-null

destroy() “While the activity's first lifecycle callback is onCreate(), its very last callback is onDestroy(). The system calls this method on your activity as the final signal that your activity instance is being completely removed from the system memory.onCreate()onDestroy() Most apps don't need to implement this method because local class references are destroyed with the activity and your activity should perform most cleanup during onPause() and onStop(). However, if your activity includes background threads that you created during onCreate() or other long-running resources that could potentially leak memory if not properly closed, you should kill them during onDestroy().”onPause()onStop()onCreate()onDestroy()

Screen Orientation Each time the screen is rotated, the current activity is destroyed, and then re-created Predefined onCreate() method retrieves state of any View components (i.e. components that sub-class View; this eases the job of the programmer This follows the call graph in fig 1. Rationale: – Typically a new layout may be needed, involving new resource allocation – Cleanest solution: always destroy and re-create Note: apps can specify to always operate in a particular orientation

Managing State Between Orientation Changes Save state information to the Bundle by overriding onStop() Re-create state by extracting information from bundle in onCreate() Discussion question: – In my Lissajous App I didn’t do this, yet state is preserved betweem orientation changes. Why?

Specifying Orientation etc Following example specifies some other details in a fairly obvious way (easiest way to find this was via a Google search) requestWindowFeature(Window.FEATURE_NO_TITLE); setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

Starting a new Activity Define a class that sub-classes Activity Add some GUI control to invoke it from the parent activity Listen for the relevant event, then launch a new Intent This will indirectly call the new Activity’s method: – onCreate(Bundle savedInstance) The new activity will start and enter then Resumed state via the call graph shown previously

The following example adds an Activity to provide information about an App A menu item called “About” is added to the options menu We listen for onOptionItemSelected events within the main activity Create an Intent, then call startActivity with the Intent as an argument When the user has finished reading the HTML page, the back button can be used to return to the main app – This behaviour is automatic use of the “back stack”: no need to program it

Intents “An intent is an abstract description of an operation to be performed.” (developer.android.com) A bit like a method call Two flavours: explicit and implicit – An explicit Intent specifies exactly which Activity should be stated – An implicit Intent is more declarative: it what the Activity should do – The system will then search for Activities that match by checking the Intent filters – Example: opening a Web Page (more on this later)

Adding the menu item to our main activity, listening for it and launching Intent public boolean onCreateOptionsMenu(Menu menu) { menu.add("About"); return true; } public boolean onOptionsItemSelected(MenuItem item) { if (item.getTitle().equals("About")) { Intent intent = new Intent(this, AboutActivity.class); startActivity(intent); return true; } return super.onOptionsItemSelected(item); } …

Discussion Point Anyone notice something non-ideal about this line of code? menu.add("About"); What’s wrong, and how would you fix it?

AboutActivity Simple example uses a hard-coded HTML file name; import statements are omitted Uses a WebView to display an HTML page specied in loadUrl method Note “android_asset” in the pathname (not “assets”) public class AboutActivity extends Activity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); WebView wb = new WebView(this); wb.loadUrl( "file:///android_asset/html/Lissajous.html"); setContentView(wb); }

Updating the AndroidManifest.xml just shows application element, new addition in bold Note that no intent filter is needed for AboutActivity, since we only need ever call this from the parent application <activity android:name="MyActivity" <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/>

Sample HTML File saved in assets/html/Lissajous.html Lissajous Curves Lissajous Curves Lissajous curves are produces by using sine functions to define parametric curves, such as the one below:

Implicit Intents Instead of specifying exactly which Activity class should handle the intent, can instead specify an action e.g. via a URL Examples: – Web browser (opened at URL) startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(" lissajous+curve")));

Example: Open a Google Map This example is almost the same as the previous one – the several step approach is optional As before, navigating back will return to the main app Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("geo:" "," )); startActivity(intent);

Summary These notes demonstrated how to start new activities using explicit and implicit intents The LissajousOne app in Lab 2 uses both types of intent (see options menu of the App) Also be aware of the App lifecycle, and which state transition methods to override in order to save and re-create state – Note: some of this happens automatically for objects of classes that inherit from View Work through the Activity Lifecycle section of lab 2