Android Application Lifecycle and Menus

Slides:



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

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
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,
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Cosc 5/4730 Blackberry and Android: Menus. BLACKBERRY.
@2011 Mihail L. Sichitiu1 Android Introduction Hello Views Part 1.
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: versions Note that: Honeycomb (Android v3.0) A tablet-only release Jelly Bean (Android v4.1) Released on July 09, 2012.
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.
Software Architecture of Android Yaodong Bi, Ph.D. Department of Computing Sciences University of Scranton.
Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.
Mobile Programming Lecture 6
@2011 Mihail L. Sichitiu1 Android Introduction GUI Menu Many thanks to Jun Bum Lim for his help with this tutorial.
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
Create Navigation Drawer Team 2 Zhong Wang Jiaming Dong Philip Wu Lingduo Kong.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Understand applications and their components activity service broadcast receiver content provider intent AndroidManifest.xml.
Android – Fragments L. Grewe.
Mobile Programming Lecture 5 Composite Views, Activities, Intents and Filters.
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.
Maps Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
Announcements Homework #2 will be posted after class due Thursday Feb 7, 1:30pm you may work with one other person No office hours tonight (sorry!) I will.
Android Using Menus Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
Mobile Programming Midterm Review
Persistence Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
Styles, Dialog Boxes, and Menus. Styles Allow creation of a common format – placed in res/values/styles.xml – file name is incidental Can be applied.
Mobile Programming Lecture 7 Dialogs, Menus, and SharedPreferences.
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Android: “Dynamic” data and Preferences data.
Designing user interfaces using: Simple views 1. Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton.
CS378 - Mobile Computing User Interface Basics. User Interface Elements View – Control – ViewGroup Layout Widget (Compound Control) Many pre built Views.
Android App Basics Slides from developer.android.com and adopted from Janzen.
Fragments and Menus Chapter 4 1. Objectives Learn three different types of menus: options, context, and popup Learn to configure the ActionBar and Toolbar.
Lab7 – Appendix.
Introduction to android
Android Programming - Features
Open Handset Alliance.
Activity and Fragment.
Adapting to Display Orientation
Mobile Application Development BSCS-7 Lecture # 6
CS499 – Mobile Application Development
Android Activities An application can have one or more activities, where Each activity Represents a screen that an app present to its user Extends the.
Android Widgets 1 7 August 2018
The Android Activity Lifecycle
תכנות ב android אליהו חלסצ'י.
ANDROID UI – FRAGMENTS UNIT II.
Android Programming Lecture 6
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Activity Lifecycle Fall 2012 CS2302: Programming Principles.
Activities and Intents
Programming Mobile Applications with Android
CIS 470 Mobile App Development
Activity Lifecycle.
CIS 470 Mobile App Development
Objects First with Java
SE4S701 Mobile Application Development
Mobile Programmming Dr. Mohsin Ali Memon.
Activities and Fragments
Activities, Fragments, and Intents
Mobile Programming Broadcast Receivers.
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
External Services CSE 5236: Mobile Application Development
Presentation transcript:

Android Application Lifecycle and Menus Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.

Application Lifecycle See flowchart in http://developer.android.com/guide/topics/fundamentals.html Active lifetime has focus, accepting UI events onResume to onPause Visible lifetime Visible, but does not have focus onStart to onStop Full lifetime onCreate to onDestroy

Active Lifetime Example Campus Maps App Shows user location on campus map image http://market.android.com/search?q=pname:com.simexusa.campusmaps_full

Active Lifetime Example Campus Maps Turn on/off GPS to save battery when UI not in focus @Override protected void onPause() { super.onPause(); //stop receiving GPS and Orientation data locationManager.removeUpdates(locationListener); } protected void onResume() { super.onResume(); //restart receiving GPS and Orientation data locationManager.requestLocationUpdates(provider, 2000, 10, locationListener);

Visible Lifetime Example Campus Maps Save state as app could get killed after onStop() @Override protected void onStop() { super.onStop(); savePreferences(); } protected void onStart() { super.onStart(); restoreUIState();

Visible Lifetime Example Campus Maps Save state as app could get killed after onStop() private void savePreferences() { SharedPreferences cmSharedPreferences = getSharedPreferences(CMPREFS,Activity.MODE_PRIVATE); SharedPreferences.Editor editor = cmSharedPreferences.edit(); editor.putBoolean(VIRTUAL_MODE, inVirtualMode); editor.putInt(MAP_INDEX, curMapIndex); editor.commit(); } private void restoreUIState() { inVirtualMode = cmSharedPreferences.getBoolean(VIRTUAL_MODE, true); curMapIndex = cmSharedPreferences.getInt(MAP_INDEX, 0);

UI Elements View Many expected Views Control ViewGroup Layout Widget (Compound Control) Many expected Views Button, CheckBox, RadioButton TextView, EditText, ListView Can be customized by extending and overriding onDraw()

XML UI Configuration Layouts can specify UI elements (provided and custom) res/layout

Campus Maps Example See res/layout/main.xml @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }

Custom View Example Campus Maps public class CampusMapView extends View { @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (image != null) { drawMapWithCircle(canvas); drawCompass(canvas); } private void drawMapWithCircle(Canvas canvas) { image.draw(canvas); //… Paint paint = new Paint(); paint.setColor(getResources().getColor(R.color.myLocationOuter)); canvas.drawCircle(circleX, circleY, 10, paint); //… };

Menus Icon Menu (up to 6 icons) Expanded Menu (from More on Icon Menu) Submenus

Static Menu Example Campus Maps : onCreateOptionsMenu @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); //Help menu menu.add(0, MENU_HELP, Menu.NONE, R.string.menu_help); //Virtual toggle menu menu.add(0, MENU_VIRTUAL, Menu.NONE, R.string.menu_item_virtual_off); if (VERSION==VERSION_SINGLE) { return true; // do no more } //Choose favorite menu SubMenu changeMapMenu = menu.addSubMenu(0, MENU_CHANGE_MAP, Menu.NONE, R.string.menu_change_map); changeMapMenu.add(0, MENU_CHANGE_0, 0, favCampusMaps[0].title); changeMapMenu.add(0, MENU_CHANGE_1, 1, favCampusMaps[1].title); changeMapMenu.add(0, MENU_CHANGE_2, 2, favCampusMaps[2].title); changeMapMenu.add(0, MENU_CHANGE_3, 3, favCampusMaps[3].title); changeMapMenu.add(0, MENU_CHANGE_4, 4, favCampusMaps[4].title); return true;

Handle Menu Selection Campus Maps : onOptionsItemSelected @Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); switch (item.getItemId()) { case MENU_HELP: { Toast.makeText(CampusMapsActivity.this, "If you don't see a map, check your internet connectivity (mobile data or wifi).", Toast.LENGTH_LONG).show(); return true; } case MENU_VIRTUAL: { if (VERSION == VERSION_TRIAL) { Toast.makeText(CampusMapsActivity.this, "Only virtual mode available in trial version.", Toast.LENGTH_LONG).show(); } else { inVirtualMode = !inVirtualMode; //toggle setupLocationService();

Dynamic Menu Example Campus Maps : onPrepareOptionsMenu @Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); MenuItem mi = null; mi = menu.findItem(MENU_VIRTUAL); if (inVirtualMode) mi.setTitle(R.string.menu_item_virtual_off); else mi.setTitle(R.string.menu_item_virtual_on); if (VERSION==VERSION_SINGLE) { return true; // do no more } if (newMapAdded) { menu.setGroupVisible(0, false); menu.setGroupVisible(1, true); else { menu.setGroupVisible(0, true); menu.setGroupVisible(1, false);