Lab 1: Getting Started With Android Programming

Similar documents
UNDERSTANDING ACTIVITIES

University of Babylon - College of IT SW Dep. - Android Assist. Lect. Wadhah R. Baiee Activities

LECTURE NOTES OF APPLICATION ACTIVITIES

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

CS378 -Mobile Computing. Anatomy of and Android App and the App Lifecycle

CS 370 Android Basics D R. M I C H A E L J. R E A L E F A L L

Developed and taught by well-known Contact author and developer. At public for details venues or onsite at your location.

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

CS 234/334 Lab 1: Android Jump Start

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

Embedded Systems Programming - PA8001

States of Activities. Active Pause Stop Inactive

Overview of Activities

Real-Time Embedded Systems

Vienos veiklos būsena. Theory

Lifecycle Callbacks and Intents

Introduction to Android development

University of Stirling Computing Science Telecommunications Systems and Services CSCU9YH: Android Practical 1 Hello World

MODULE 2: GETTING STARTED WITH ANDROID PROGRAMMING

CS 528 Mobile and Ubiquitous Computing Lecture 3b: Android Activity Lifecycle and Intents Emmanuel Agu

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

INTRODUCTION TO ANDROID

COMP4521 EMBEDDED SYSTEMS SOFTWARE

Computer Science E-76 Building Mobile Applications

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

CS378 - Mobile Computing. Anatomy of an Android App and the App Lifecycle

Programming Mobile Applications with Android Lab2

Android for Ubiquitous Computing Researchers. Andrew Rice University of Cambridge 17-Sep-2011

Lab 3: Using Worklight Server and Environment Optimization Lab Exercise

Android Programmierung leichtgemacht. Lars Vogel

Programming Mobile Applications with Android Lab1

Create new Android project in Android Studio Add Button and TextView to layout Learn how to use buttons to call methods. Modify strings.

Activities. Repo:

Application Fundamentals

Android Programming Lecture 2 9/7/2011

CPET 565 Mobile Computing Systems CPET/ITC 499 Mobile Computing. Lab & Demo 2 (Part 1-2) Hello-Goodbye App Tutorial

Android Activities. Akhilesh Tyagi

Programming Concepts and Skills. Creating an Android Project

COSC 3P97 Mobile Computing

Android Workshop: Model View Controller ( MVC):

EMBEDDED SYSTEMS PROGRAMMING Application Basics

Minds-on: Android. Session 2

Solving an Android Threading Problem

Android. Mobile operating system developed by Google A complete stack. Based on the Linux kernel Open source under the Apache 2 license

ES E 3 3 L a L b 5 Android development

CPET 565 Mobile Computing Systems CPET/ITC 499 Mobile Computing. Lab & Demo 2 (1 &2 of 3) Hello-Goodbye App Tutorial

CMSC436: Fall 2013 Week 3 Lab

application components

Lab Android Development Environment

Android development. Outline. Android Studio. Setting up Android Studio. 1. Set up Android Studio. Tiberiu Vilcu. 2.

Android Basics. Android UI Architecture. Android UI 1

Android Application Development

Android Ecosystem and. Revised v4presenter. What s New

ECOM 5341 Mobile Computing(Android) Eng.Ruba A. Salamah

Lifecycle-Aware Components Live Data ViewModel Room Library

Applications. Marco Ronchetti Università degli Studi di Trento

CS 528 Mobile and Ubiquitous Computing Lecture 3: Android UI, WebView, Android Activity Lifecycle Emmanuel Agu

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters

Android Basics. - Bhaumik Shukla Android Application STEALTH FLASH

Android Beginners Workshop

Fragments were added to the Android API in Honeycomb, API 11. The primary classes related to fragments are: android.app.fragment

Activities and Fragments

Configuring the Android Manifest File

Mobile Programming Lecture 1. Getting Started

COLLEGE OF ENGINEERING, NASHIK-4

Have a development environment in 256 or 255 Be familiar with the application lifecycle

Basic Android Setup for Machine Vision Fall 2015

Android Fundamentals - Part 1

Understanding Application

Mobila applikationer och trådlösa nät, HI1033, HT2012

Introduction To Android

Android HelloWorld - Example. Tushar B. Kute,

Android Debug Framework

CS 4518 Mobile and Ubiquitous Computing Lecture 4: Data-Driven Views, Android Components & Android Activity Lifecycle Emmanuel Agu

Mobile User Interfaces

Mobile Programming Lecture 2. Layouts, Widgets, Toasts, and Event Handling

Getting started: Installing IDE and SDK. Marco Ronchetti Università degli Studi di Trento

GUI Design for Android Applications

Figure 2.10 demonstrates the creation of a new project named Chapter2 using the wizard.

Building MyFirstApp Android Application Step by Step. Sang Shin Learn with Passion!

Mobile Application Development - Android

Tablets have larger displays than phones do They can support multiple UI panes / user behaviors at the same time

Google Maps Troubleshooting

UI Fragment.

CS 4518 Mobile and Ubiquitous Computing Lecture 5: Rotating Device, Saving Data, Intents and Fragments Emmanuel Agu

LifeStreet Media Android Publisher SDK Integration Guide

Lab 1 - Setting up the User s Profile UI

Wirtschaftsinformatik Skiseminar ao. Prof. Dr. Rony G. Flatscher. Seminar paper presentation Dennis Robert Stöhr

Steps to Set Up the Environment of Xamarin in Visual

Mobile Application Development

Security model. Marco Ronchetti Università degli Studi di Trento

Mobile OS. Symbian. BlackBerry. ios. Window mobile. Android

CE881: Mobile & Social Application Programming

Android Coding. Dr. J.P.E. Hodgson. August 23, Dr. J.P.E. Hodgson () Android Coding August 23, / 27

Fig. 2.2 New Android Application dialog. 2.3 Creating an App 41

Login with Amazon. Getting Started Guide for Android apps

Hello World. Lesson 1. Create your first Android. Android Developer Fundamentals. Android Developer Fundamentals

1. Location Services. 1.1 GPS Location. 1. Create the Android application with the following attributes. Application Name: MyLocation

CMSC 436 Lab 10. App Widgets and Supporting Different Devices

By Ryan Hodson. Foreword by Daniel Jebaraj

Transcription:

Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Eng. Jehad Aldahdooh Mobile Computing Android Lab Lab 1: Getting Started With Android Programming To create a new Android Project follows the steps: 1. Open Eclipse. 2. Click the menu File New Android Application Project 1

3. Name the project : In this stage, as shown below there are exist three names described as: Application Name Shown in Play Store and Settings.Usually same as Project Name. Project Name Eclipse project name. Follow naming convention you use for Eclipse. Not used elsewhere. Package name Apps on a particular Android device must have unique packages, so use com.yourcompany.project 2

Target Build SDK The Android version used to build/compile your project. This can be any version, but the safest option is to make it match the minimum SDK below. Minimum Required SDK The Android version that you want to run on. 4. Click Next 5. Configure Launcher Icon Purpose To choose the picture displayed on the Android device, that, when clicked, launches the app. Defaults Use defaults for development and testing. Just press Next. 3

6. Choose Blank Activity Options for Blank Activity: Activity Name Name of main Java class. This is the class you will edit first. Class name often corresponds to project name. Layout Name Base name of XML file in res/layout folder. Used to give layout to app. often just called main. Will be referred to in main Java class with R.layout.layout_name. 4

5

Anatomy of an Android Application Source Code Version of the library you had chosen Resources that your application may need Use to construct user interfaces Value type resources, such as string Java files autogenerated by ADT Anything stored in the 'assets' folder has to be accessed in the classic 'file' manipulation style Hold image and animation files that you can use in your Contains all the information about the application 6

Run Hello World on the Emulator and Phone First: On the Emulator Before we can run the application, we need to setup an Android Vitual Device(AVD), or emulator, to run it on: Select the menu Window -> "Android SDK and AVD Manager". Select Virtual Devices on the left hand side. Click the New... button. Give your AVD a name. Select the target build that we would like to run the application on Click Create AVD and close out the SDK/AVD Manager. We're now ready to run our application. Select the menu Run -> Run. Note: The emulator may take a long time to start up. Note: Another way to run your application is to right-click on the project in the Package Explorer, then select Run As -> Android Application. 7

Second: On a Physical Device Project Modifications From the Package Explorer, double-click the file AndroidManifest.xml. Select the tab labeled AndroidManifest.xml along the bottom. Add android:debuggable="true" to the inside of the opening <application> tag. Save the file and close it. Phone Modifications o Select Settings -> Applications -> Development. o Enable the USB debugging option Ensure the device is properly connected. Run the application as you would normally. 8

Three Main Approaches in Android Programming 1. Java-based 1. XML-based 2. Hybrid Use Java to define Strings, lay out window, create GUI controls, and assign event handlers. Like Swing programming. Use XML files to define Strings, lay out window, create GUI controls, and assign event handlers. The Java method will read the layout from XML file and pass it to setcontentview. Use an XML file to define Strings, layout window and create GUI controls. Use Java to assign event handlers. 1. Java-Based Approach: Template Approach Use Java to define Strings, layout window, create GUI controls, and assign event handlers. Advantages Familiar to Java desktop developers. Like approach used for Swing, SWT, and AWT. Good for layouts that are dynamic (i.e., that change based on program logic). Disadvantages Harder to maintain. Not generally recommended except for dynamic layouts. But still acceptable for App Store. Whatever works best for your programmers and your app. No code police. 9

OnClickListener is a public inner class inside View. But, as long as you import android.view.view.onclicklistener, you use it just like a normal class. And, remember that Eclipse helps you with imports: just type in the class name. 2. XML-Based Approach: Template Approach Use XML files to define Strings, layout window, create GUI controls, and assign event handlers. Define layout and controls in res/layout/main.xml Define Strings in res/values/strings.xml Advantages Easier to maintain Can use visual layout editor in Eclipse 10

Disadvantages Works poorly for dynamic layouts 3. Hybrid Approach: Template 11

Activity Class Activity: Much like a Form for a web page, activities display a user interface for the purpose of performing a single task. An example of an Activity class would be one which displays a Login Screen to the user. Create the Activity Class create a new class that extends android.app.activity class and implements android.view.view.onclicklistener interface. Add a method with the following signature: public void oncreate(bundle savedinstancestate). o This method will be called when the Activity starts and is where initialization of local and member data will be done. Inside this method perform the following: 12

o make a call to super.oncreate(savedinstancestate) This should always be done and is to ensure that any necessary parent class initializations are performed. o make a call to this.setcontentview(r.layout.activity_main) When you created the XML layout file earlier, the Android Eclipse Plugin automatically added a static constant to the static R.layout class in the R.java file under the /gen folder. This constant variable has the same name of the file and it's value is used to identify the layout file. This call tells Android to create a screen based off of the layout file. o Make a call to this.findviewbyid(r.id.button) and set your Button member variable equal to the return value. Implement the OnClickListener interface by creating a method stub with the following signature: public void onclick(view v). Android Lifecycle The Activity base class defines a series of events that govern the life cycle of an activity. The Activity class defines the following events: oncreate() Called when the activity is first created onstart() Called when the activity becomes visible to the user onresume() Called when the activity starts interacting with the user onpause() Called when the current activity is being paused and the previous activity is being resumed onstop() Called when the activity is no longer visible to the user ondestroy() Called before the activity is destroyed by the system (either manually or by the system to conserve memory onrestart() Called when the activity has been stopped and is restarting again 13

14

15

1. Run the application. 2. When the activity is first loaded, you should see something very similar to the following in the LogCat window In the oncreate() event In the onstart() event In the onresume() event 3. If you click the Back button on the Android emulator, the following is printed: In the onpause() event In the onstop() event In the ondestroy() event 4. Click the Home button and hold it there. Click the Activities icon and observe the following: In the oncreate() event In the onstart() event In the onresume() event 5. Click the Phone button on the Android emulator so that the activity is pushed to the background.observe the output in the LogCat window: In the onpause() event In the onstop() event 6. Notice that the ondestroy() event is not called, indicating that the activity is still in memory. Exit the phone dialer by clicking the Back button. The activity is now visible again. Observe the output in the LogCat window: In the onrestart() event In the onstart() event In the onresume() event 16