CMPE419 Mobile Application Development

Slides:



Advertisements
Similar presentations
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.
Advertisements

Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Crash Course in Android Development. 2 Content  Installing the ADT  Hardware and OS requirements  Java  ADT Bundle  Eclipse Project Setup  Drawing.
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
Android Development (Basics)
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Android Application Development 2013 PClassic Chris Murphy 1.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Social Media Apps Programming Min-Yuh Day, Ph.D. Assistant Professor Department of Information Management Tamkang University
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Android - Broadcast Receivers
Networking: Part 1 (Web Content). Networking with Android Android provides A full-featured web browser based on Chromium, the open source browser engine.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
First Venture into the Android World Chapter 1 Part 2.
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.
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Introduction to Android Chapter 1 1. Objectives Understand what Android is Learn the differences between Java and Android Java Examine the Android project.
Android Programming.
Lab7 – Appendix.
Introduction to android
Android Programming - Features
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
Android Application Development 1 6 May 2018
Adapting to Display Orientation
CS240: Advanced Programming Concepts
GUI Programming Fundamentals
Mobile Application Development Chapter 3 [Using Eclipse Android Studio for Android Development] IT448-Fall 2017 IT448- Fall2017.
Mobile Computing With Android ACST 4550 Intro to Android, Part 1
Android Studio, Android System Basics and Git
Android Introduction Hello World.
Android Widgets 1 7 August 2018
Mobile Device Development
Anatomy of an Android Application
Android SDK & App Development
Software Engineering for Internet Applications
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
Chapter 1: Basics of Android, First App: HelloAndroid
Android Topics Android Activity Lifecycle and Experiment Toast
Android Developer Fundamentals V2 Lesson 1
HNDIT2417 Mobile Application Development
Activities and Intents
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android Project Structure, App Resources and Event Handling
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
Chapter 5 Your Second Activity.
Mobile Programming Broadcast Receivers.
Android Sensor Programming
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren 2018-2019 SPRING Computer Engineering Department CMPE419 AU

Installation: https://developer.android.com/sdk/index.html

Android Introduction Hello World

Goal Create a very simple application Run it on a real device Run it on the emulator Examine its structure Start a new project Step 1: Start and configure the project Step 2: Select form factors and API level Step 3: Add an activity Step 4: Configure your activity

Your First Application To begin creating an Android application, go with the Java perspective and select  File > New Project. Doing so will launch the application creation wizard, and you will be prompted to enter meta-information about your project in three categories: Contents, Build Target, and Properties.

Project Structure Each project in Android Studio contains one or more modules with source code files and resource files. Types of modules include: Android app modules Library modules Google App Engine modules By default, Android Studio displays your project files in the Android project view, as shown in figure 1. This view is organized by modules to provide quick access to your project's key source files. All the build files are visible at the top level under Gradle Scripts and each app module contains the following folders: manifests: Contains the AndroidManifest.xml file. java: Contains the Java source code files, including JUnit test code. res: Contains all non-code resources, such as XML layouts, UI strings, and bitmap images. The Android project structure on disk differs from this flattened representation. To see the actual file structure of the project, select Project from the Project dropdown (in figure 1, it's showing asAndroid). You can also customize the view of the project files to focus on specific aspects of your app development. For example, selecting the Problems view of your project displays links to the source files containing any recognized coding and syntax errors, such as a missing XML element closing tag in a layout file.

All source code here (packages and activities) Java code for our activity All non-code resources Images Layout of the activity Strings used in the program Android Manifest

The AndroidManifest.xml file The AndroidManifest.xml file provides metadata about your application that the Android OS will need to run the app properly. The name of the application, used for both the app icon and the activity titlebar, and the app icon are defined under Application Attributes. You will notice that the Name field doesn't actually contain the name text, but "@string/app_name" instead. This is a string reference and can be used anytime a string is expected. The actual string text is then defined in one of the XML files found under the res/values folder. The app creation wizard generated a file there called strings.xml. The Application Nodes section is where all the activities are defined for the application. Our app's single activity is called MainActivity and listed here.

Java Code package com.example.pc.cmpe419_1; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return super.onOptionsItemSelected(item);

XML files Activiti_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.helloworld.HelloMainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout>

String.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">HelloWorld</string> <string name="hello_world">Hello world!</string> </resources>

androidmanifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.helloworld" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

With application name package com.example.helloworld; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; public class HelloMainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_main); }

Import an existing project To import an existing project into Android Studio, proceed as follows: Click File > New > Import Project. In the Select Eclipse or Gradle Project to Import window that appears, navigate to the root directory of the project you want to import. Click OK. Android Studio then opens the project in a new IDE window. If you are importing a project from version control, use the File > New > Project from Version Control menu. For more information about importing projects from version control, read IntelliJ’s VCS-Specific Procedures. If you are importing an existing Eclipse ADT project into Android Studio, how you add the project depends on its structure. To read more about importing projects from Eclipse, see Migrate to Android Studio from Eclipse.

Write and View Logs with Logcat The Logcat window in Android Studio displays system messages, such as when a garbage collection occurs, and messages that you added to your app with the Log class. It displays messages in real time and keeps a history so you can view older messages.

Write log messages The Log class allows you to create log messages that appear in logcat. Generally, you should use the following log methods, listed in order from the highest to lowest priority (or, least to most verbose): Log.e(String, String) (error) Log.w(String, String) (warning) Log.i(String, String) (information) Log.d(String, String) (debug) Log.v(String, String) (verbose)

Examples Log.i("Hi", "Internet connection created"); Log.w("OOps", "Password wrong"); public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.i("LogHi", "Your first program."); try { int c = 7 / 0; } catch (Exception err) { Log.e("LogHi", «Serrious error: " + err.getLocalizedMessage()); } }

Activity An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View). While activities are often presented to the user as full-screen windows, they can also be used in other ways: as floating windows (via a theme with windowIsFloating set) or embedded inside of another activity (using ActivityGroup). There are two methods almost all subclasses of Activity will implement: onCreate(Bundle) is where you initialize your activity. Most importantly, here you will usually call setContentView(int) with a layout resource defining your UI, and using findViewById(int) to retrieve the widgets in that UI that you need to interact with programmatically. onPause() is where you deal with the user leaving your activity. Most importantly, any changes made by the user should at this point be committed (usually to the ContentProvider holding the data). To be of use with Context.startActivity(), all activity classes must have a corresponding <activity> declaration in their package's AndroidManifest.xml.

Activity Lifecycle