1 Mobile Computing Java, Android, and Eclipse Copyright 2015 by Janson Industries.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
Tutorial 8: Developing an Excel Application
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
The Web Warrior Guide to Web Design Technologies
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.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
1 Mobile Computing Mobile First (formerly Worklight) Copyright 2015 by Janson Industries.
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
Getting Started with Android Programming Note: if you have already installed android development tools, please check that you have the same version as.
1 CGS1060 Mobile UIs Copyright 2012 by Janson Industries.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Android Programming. Outline Preparation Create new project Build and Run a project Debug a project Deploy on devices.
Android Application Development 2013 PClassic Chris Murphy 1.
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
A First Program Using C#
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
CS5103 Software Engineering Lecture 08 Android Development II.
1 Mobile Computing Set Up Copyright 2015 by Janson Industries.
Using Eclipse. What is Eclipse? The Eclipse Platform is an open source IDE (Integrated Development Environment), created by IBM for developing Java programs.
Chapter 1a© copyright Janson Industries RAD ▮ Explain Eclipse, RAD, and their relationship ▮ Basic RAD concepts ▮ How to install RAD ▮ How to import.
1 Mobile Computing Monetizing An App Copyright 2014 by Janson Industries.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
Mail merge I: Use mail merge for mass mailings Perform a complete mail merge Now you’ll walk through the process of performing a mail merge by using the.
Activities and Intents. Activities Activity is a window that contains the user interface of your application,typically an application has one or more.
Drexel University Software Engineering Research Group 1 Eclipse for SE101.
Chapter 1© copyright Janson Industries Java ▮ Java programming concepts ▮ Downloading the JDK ▮ Java coding and executing example This presentation.
© 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.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
The Java Programming Language
Copyright © Curt Hill Java Looking at our first console application in Eclipse.
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
9/2/ CS171 -Math & Computer Science Department at Emory University.
Android Hello World 1. Click on Start and type eclipse into the textbox 2.
Noname. Conceptual Parts States of Activities Active Pause Stop Inactive.
First Venture into the Android World Chapter 1 Part 2.
Mobile Programming Lecture 3 Debugging. Lecture 2 Review What widget would you use to allow the user to enter o a yes/no value o a range of values from.
Chapter 2© copyright Janson Industries Java ▮ Java/PC programming environment ▮ Java syntax rules ▮ Java documentation ▮ Java/RAD coding example.
Creating a Java Application and Applet
Chapter 4© copyright Janson Industries More GUI ▮ Events, Actions, and Listeners ▮ The Visual Editor ▮ More GUI component properties Non-graded assg.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Programming in java Packages Access Protection Importing packages Java program structure Interfaces Why interface Defining interface Accessing impln thru.
Intoduction to Andriod studio Environment With a hello world program.
OOP Basics Classes & Methods (c) IDMS/SQL News
Editing and Debugging Mumps with VistA and the Eclipse IDE Joel L. Ivey, Ph.D. Dept. of Veteran Affairs OI&T, Veterans Health IT Infrastructure & Security.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Using Macros Lesson.
Chapter 1a© copyright Janson Industries RAD ▮ Explain Eclipse, RAD, and their relationship ▮ Basic RAD concepts ▮ How to install RAD ▮ How to import.
Fundamentals of Windows Mouse n 4 Basic Operations: –Pointing –Clicking –Double Clicking –Dragging.
Introduction to android
Eclipse Navigation & Usage.
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
The Android Activity Lifecycle
CIS 470 Mobile App Development
How to Run a Java Program
Activities and Intents
CIS 470 Mobile App Development
Using Eclipse.
Java Looking at our first console application in Eclipse
Activities, Fragments, and Intents
CIS 694/EEC 693 Android Sensor Programming
How to Run a Java Program
Presentation transcript:

1 Mobile Computing Java, Android, and Eclipse Copyright 2015 by Janson Industries

2 Objectives ▀ Explain u Application organization in Eclipse u Basic Java concepts u How to code and run an Android app in the emulator u Controlling the emulator u The Android app life cycle

Copyright 2015 by Janson Industries 3 Eclipse ▀ Has a variety of perspectives u Java, Debug, DDMS ▀ Each perspective consists of a unique set of functions and views of the application resources u Java shows source code and allows the programmer to edit it u Debug shows the stack trace (logic flow) of a running app u DDMS allows access to the device/emulator’s file system

Copyright 2015 by Janson Industries 4 Perspective indicated in upper right hand corner Java Perspective window initially consists of 6 panes – only need 4. Can close Task List and Connect Mylyn Resize panes by clicking and dragging borders Double click view tab to expand view and fill perspective window Panes contain views Views indicated by tabs at top of pane, switch view by clicking tab

Copyright 2015 by Janson Industries 5 Can have multiple perspectives open but only one is active

Copyright 2015 by Janson Industries 6 Open a new perspective by clicking Window, Open Perspective, then choose a perspective Switch between perspectives by clicking perspective button

Copyright 2015 by Janson Industries 7 Eclipse ▀ All of an application’s resources are stored in a project u Source code u Images u XML ▀ The resources can be further organized into folders and packages

Copyright 2015 by Janson Industries 8 Project Package Folder Package Folder File Eclipse ▀ Packages and folders hold the majority of an application’s resources u Source code u Images u XML ▀ Java source code must go into a package

Copyright 2015 by Janson Industries 9 Android Java ▀ An Android application’s programs are called activities ▀ Files with an extension of.java hold an activity’s source code ▀ To create an activity you have to have a project and a package to put it in

Copyright 2015 by Janson Industries 10 Creating an Application ▀ Click File, New and then Project ▀ Select Android Project ▀ Specify: u Project, package, activity and application names u A build target

Copyright 2015 by Janson Industries 11 Click File, New, and Project then expand Android, select Android Application Project and click Next

Copyright 2015 by Janson Industries 12 Give names to the Application (Howdy), Project (MyFirstProject), Package (my.first.pkg), specify 2.1, click Next

Copyright 2015 by Janson Industries 13 n Click Next Creating an Application

Copyright 2015 by Janson Industries 14 n Can create a unique icon n We’ll accept default and click Next Creating an Application

Copyright 2015 by Janson Industries 15 n Will create a Hello World activity for us n Click Next Creating an Application

Copyright 2015 by Janson Industries 16 n Change activity name to HowdyActivity n Click Finish Creating an Application

Copyright 2015 by Janson Industries 17 Creating an Application n Eclipse will create the u Project u Packages and folders u Files n It even creates a working application u In a file called HowdyActivity.java u File stored in a package called my.first.pkg in source folder src

Copyright 2015 by Janson Industries 18 To Run an Application n In Package Explorer, expand MyFirstProject, src, & my.first.pkg n Right click HowdyActivity and select Run As then Run Configurations n Select Android Application and click the New button

Copyright 2015 by Janson Industries 19

Copyright 2015 by Janson Industries 20 Give the configuration a name and specify the Project Click Apply and Run

Copyright 2015 by Janson Industries 21 To Run an Application n First time will take a while n Emulator must configure itself and will launch n The emulator is displayed u You have to click and drag the lock icon to see the results of the activity

Copyright 2015 by Janson Industries 22 Click and drag the lock icon to the right

Copyright 2015 by Janson Industries 23 If app doesn’t start, rerun in Eclipse

Copyright 2015 by Janson Industries 24 Console should show that app was installed just not run

Copyright 2015 by Janson Industries 25 Voila!

Copyright 2015 by Janson Industries 26 To Run an Application n Once emulator is running, results will be shown must faster n To close emulator: u Right click Android button in the System Tray u Select Close Window u Or click the Close Window button n Can control the size of the emulator

Copyright 2015 by Janson Industries 27 Control Emulator Size n Run emulator before running an activity. Click: u Window (in the command bar) u AVD Manager u Select the AVD u Click Start u Click Scale display to real size u Specify screen size u Click Launch

Copyright 2015 by Janson Industries

Copyright 2015 by Janson Industries 29 If it shows, accept the default video source

Copyright 2015 by Janson Industries 30 New size fits on the screen better Need to go back and close AVD Manager window

Copyright 2015 by Janson Industries 31 How Does It Work n The generated application is pretty complicated and requires a lot of Java knowledge n Let’s first learn some Java (then some XML) and then generate our own application u Later we will cover the workings of the generated application

Copyright 2015 by Janson Industries 32 Java n Java programs are called classes n Classes are stored in files that have an extension of.java n Classes are comprised of a header and a body

Copyright 2015 by Janson Industries 33 Java Class n Class header defines: u The source code as a class (e.g. “class” keyword is used) u Access allowed (e.g. “public”) u The name of class F Must begin with an upper case letter F Is case sensitive F Cannot contain spaces F Must match.java file name prefix I.e. a class named Customer must be in a file named Customer.java

Copyright 2015 by Janson Industries 34 Java Class n The class body is enclosed in braces {} and comprised of class/global variables and methods n Simple class example: public class ClassName { global variable definition method{} }

Copyright 2015 by Janson Industries 35 Java Method n Comprised of a header and body n Header definition comprised of: u Modifiers (e.g. “private”, “public”, “static”) u Return value (e.g. “void”, “String”) u Method name F Begins with a lower case letter (e.g. getMailingLabel, main) u Parameter(s)/received value(s) in parenthesis (e.g. (String name), (int age), () means no params)

Copyright 2015 by Janson Industries 36 Java Method Header n Method header/definition examples: u public void setName(String custName) u public String getMailingLabel() u public static void main(String[ ] args) F A static method can be run all by itself’ It is self sufficient/stand alone n If multiple values passed/received simply separate by commas u (String itemName, int itemPrice)

Copyright 2015 by Janson Industries 37 Java Method Header n Private methods: u Can only be accessed/run by other methods within the class n Public methods: u Can be accessed by objects external to the class u Are considered the class “interface” F This is how other classes/objects can interface with this class

Copyright 2015 by Janson Industries 38 Java Method Body n Enclosed in braces { } n Comprised of: u Local variable definitions u Executable statements n Variable definition comprised of: u The variable type u The variable name u A semicolon (;)

Copyright 2015 by Janson Industries 39 Java Method Body n Variable definition examples int age; String customerName; double salary; String street, city, state, zip; n In addition, variable definitions can u Specify access modifiers u Initialize the variable

Copyright 2015 by Janson Industries 40 Java Method Body n Variable definition examples private int age = 22; String customerName = new String( “Joe”) ; double salary = ; public String street, city, state, zip; n Executable statements also must end in semicolons u System.out.println(“Howdy”);

Copyright 2015 by Janson Industries 41 Java Method Body Example public void onCreate(Bundle aBundle) { super.onCreate(aBundle); String greeting = new String(“******Hello*******”); System.out.println(“A print of static text"); System.out.println(“The value of greeting is: ” + greeting); } statements variable definition

Copyright 2015 by Janson Industries 42 Classes n If a class is stored in a package, the class must have a package statement at the very beginning of the source code n So for example, the HowdyActivity class has the following: package my.first.pkg;

Copyright 2015 by Janson Industries 43 Activity Classes n Activity classes are executable n Some special requirements u The class must be defined as an acitivty u When first run, the activity’s onCreate method will be executed u onCreate must F accept a Bundle object F call it’s superclass’ onCreate method and pass the bundle

Copyright 2015 by Janson Industries 44 Superclass n All classes are related in a hierarchy n This parent/child relationship is called a superclass/subclass relationship for java classes u Just like in real life the child/subclass inherits all the parent/superclass’ variables and methods

Copyright 2015 by Janson Industries 45 Superclass n For example, an EditText class is a visual component that a user can enter text into n This is it’s lineage: Object View TextView EditText

Copyright 2015 by Janson Industries 46 Import Statements n All the java classes in the SDK are stored in packages n To use these classes you can specify the location (i.e. the package(s) that hold them u android.app.Activity u android.os.Bundle n This is called a fully qualified file reference

Copyright 2015 by Janson Industries 47 Import Statements n Fully qualified file references mean extra typing and more errors n If import statements are added we can use non-fully qualified file references for the classes (Activity, Bundle ) import android.app.Activity; import android.os.Bundle;

Copyright 2015 by Janson Industries 48 Import Statements n The import statements come after the package statement but before the class header n Now if we want to use the Bundle class we can type u Bundle n Instead of u android.os.Bundle

Copyright 2015 by Janson Industries 49 Import Statements n So you can use fully qualified file references like this : n Or use import statements and non- fully qualified file references like this : public void onCreate(Bundle aBundle) { public void onCreate(android.os.Bundle aBundle) {

Copyright 2015 by Janson Industries 50 Activity Classes n To define the class as an activity (I.e. a subclass of the Activity class) an extends clause must be included in the class header as follows: n Comments (non-executable statements) preceded by // public class HowdyActivity extends Activity {

Copyright 2015 by Janson Industries 51 Putting It All Together package my.first.pkg; //Identifies the package the class is in import android.app.Activity; //Identifies the location of classes import android.os.Bundle; //this class will be using public class HowdyActivity extends Activity { //Class header //Method header public void onCreate(Bundle savedInstanceState) { //Superclass’ onCreate method invoked super.onCreate(savedInstanceState); //String variable defined and initialized String greeting = new String("******Hello*******"); //Two lines of text are displayed System.out.println("A print of static text"); System.out.println("The value of greeting is: " + greeting); }

Copyright 2015 by Janson Industries 52 Putting It All Together n So in HowdyActivity: u Comment out the one setContentView statement F Precede the statement with // F Keystroke short cut: Select the statement Click Ctrl+/ u After the commented out statement, add the three statements from the previous slide that F Create the String variable F Display the two lines of text

Copyright 2015 by Janson Industries 53 Putting It All Together n Code should look like this

Copyright 2015 by Janson Industries 54 Running the New App n In the Package Explorer view, select the MyFirstProject n Click the Run button (green circle with white arrow head) n You’ll be prompted to save the changes n Click Yes n Nothing happened!?! u This gives us the opportunity to introduce LogCat

Copyright 2015 by Janson Industries 55 LogCat n LogCat holds all the system generated msgs and any println statements run in the code n If LogCat not displayed at bottom of window, display by clicking: u Window u Show View u Other u Android (to expand it) u LogCat u OK

Copyright 2015 by Janson Industries 56 LogCat n If your LogCat has no msgs (as below) it is because the emulator doesn’t have “focus”

Copyright 2015 by Janson Industries 57 Switch to DDMS perspective (Window, Open Perspective) and click on the emulator in the Devices view

Copyright 2015 by Janson Industries 58 If nothing appears, click the down arrow and select Reset adb Emulator will be redisplayed

Copyright 2015 by Janson Industries 59 Go back to the Java perspective and scroll to the right in LogCat to display all the text Common mistake: looking at the console not LogCat

Copyright 2015 by Janson Industries 60 If app rerun, info will not be redisplayed because app is already created Prove by clearing LogCat and rerunning

Copyright 2015 by Janson Industries 61 New system msgs will be there but not the text from the app This brings up the Android application life cycle!

Copyright 2015 by Janson Industries 62 Application Life Cycle ▀ There are 4 states that an application can be in u Active: the activity can be used by the user u Paused: The activity is partially obscured (a new non-full screen or transparent activity is active) u Stopped: The activity is totally obscured (a new full screen activity is active) u Finished: the activity has been closed.

Copyright 2015 by Janson Industries 63 Application Life Cycle ▀ Based on changes in the application’s “state”, several other methods will be called : u protected void onStart(){} u protected void onRestart(){} u protected void onResume(){} u protected void onPause(){} u protected void onStop(){} u protected void onDestroy(){}

Copyright 2015 by Janson Industries 64 Application Life Cycle ▀ An application’s “state” can be changed by user actions like: u Starting a new application u Closing an application ▀ What the new state will be will vary by what is being run u Does new app take up the whole screen? u Is there enough MM for new app?

Copyright 2015 by Janson Industries 65 Application Life Cycle ▀ For example, when an app is first run it means the following methods will be run: u onCreate() u onStart() u onResume() ▀ Let’s prove it!

Copyright 2015 by Janson Industries 66 Application Life Cycle ▀ We’ll add the following two new methods: ▀ And change onCreate a little protected void onStart(){ super.onStart(); System.out.println("*****onStart was run"); } protected void onResume(){ super.onStart(); System.out.println("*****onResume was run"); }

Copyright 2015 by Janson Industries 67 Here’s all the new code

Copyright 2015 by Janson Industries 68 Application Life Cycle ▀ Need a new emulator with the buttons enabled ▀ Need to clone a definition u Only user defined emulators can be edited ▀ Start the AVD manager

Copyright 2015 by Janson Industries 69 Click Device Definitions tab then Double click Galaxy Nexus definition Edit definition, click Clone Device

Copyright 2015 by Janson Industries 70 ▀ Define new AVD ▀ Select the first Galaxy Nexus listed ▀ If correct one selected, RAM will be 512 ▀ Fill in rest of info

Copyright 2015 by Janson Industries 71 Select and Start the new emulator

Copyright 2015 by Janson Industries 72 Run app and LogCat shows the msgs

Copyright 2015 by Janson Industries 73 In emulator, click home button to stop the app Run the app again

Copyright 2015 by Janson Industries 74 Scroll up and notice onCreate was not run, that’s because app was already created but stopped

Copyright 2015 by Janson Industries 75 The Whole Thing Active Activity Started on Start on Resume on Create on Pause PausedStopped on Stop on Restart Finished on Destroy Whoa! Maybe we should go step by step

Copyright 2015 by Janson Industries In the Beginning 76 Active Activity Started on Start on Resume on Create ▀ When the application is first run…

Copyright 2015 by Janson Industries From an Active State 77 ▀ The application can go to any of the other three states… Active on Pause Paused on Stop Active on Pause Finished on Destroy Active on Pause Stopped on Stop

Copyright 2015 by Janson Industries From an Paused State 78 ▀ The application can go Active or Stopped states… Paused Stopped Active on Resume on Stop

Copyright 2015 by Janson Industries From an Stopped State 79 ▀ The application can go to Finished or Active states… Active on Restart Finished on Destroy Stopped on Start on Resume

Copyright 2015 by Janson Industries 80 Android App Life Cycle ▀ Why all the different methods? ▀ You might want the app to do different functions when the state is changed u When closed, free up resources u When restarted, refresh info on screen u When paused, stop playing music

Copyright 2015 by Janson Industries 81 Emulator Glitches ▀ When emulator run, message that says something like: u Image is used by another emulator ▀ Need to go out and delete these two files in the emulator definition ▀ Substituting for username and emulator name C:/Users/username/.android/avd/EmulatorName/cache.img C:/Users/username/.android/avd/EmulatorName/userdata-qemu.img

Copyright 2015 by Janson Industries 82 Emulator Glitches ▀ If it starts running slowly or if logcat isn’t working well u Not displaying msgs quickly u Not allowing msg deletions ▀ Restart Eclipse ▀ Gives Eclipse a chance to clean up internally

Copyright 2015 by Janson Industries 83 Emulator Glitches ▀ If you get this msg: u ADB server didn't ACK, failed to start daemon ▀ Start Task Manager and kill the adb.exe process ▀ Close and restart Eclipse

Copyright 2015 by Janson Industries 84 Points to Remember ▀ Java classes stored in a project's package ▀ Java class consists of global level variables and methods ▀ Java method consists of local level variables and executable statements ▀ Activity classes are executable

Copyright 2015 by Janson Industries 85 Points to Remember ▀ LogCat displays system and program msgs ▀ An app can be in four states u Active u Paused u Stopped u Finished ▀ Changes in state will result in different methods being executed