Ii 1300-java essentials for android
-
Upload
adrian-mikeliunas -
Category
Technology
-
view
982 -
download
4
description
Transcript of Ii 1300-java essentials for android
Java Essentials for Android
Presented by
Adrian Mikeliunas
TASKMobileSolutions.com
Java Essentials for Android
2
MoDevAcademy
MoDevAcademy will offer professional training across platforms that include beginner, intermediate and advanced courses.
The format will be one day courses that can be taken individually or paired for a multi-day experience. The Academy intended to fill a much needed void in the market for in-depth mobile developer training.
Upcoming Classes
Schedule:
• January 22nd: Starting up with iOS Development
• January 23rd: Expert Objective-C
• January 24th: Advanced Xcode Development
Register at MoDevAcademy.com/Registration
Online Resources
The references in this presentation, and many other resources are available at:
http://Gomodev.com/MoDevAcademyResources
Java Essentials for Android
5
Agenda
Java Similarities
Java Differences
Android Programming with Java in Eclipse
Resources Google Samples F-droid.org SourceFourge.net
Java Essentials for Android
6
Android & Java ComparisonsSimilarities
Differences
Java Essentials for Android
7
Android <> Java
Android is Google’s Operating System, combining Linux with their own version of Java, named Dalvik
Dalvik uses a subset of Harmony, an Apache Software Foundation project
Dalvik is open-source software. Is the name of a fishing village in Iceland
http://en.wikipedia.org/wiki/Dalvik_virtual_machine
Java Essentials for Android
8
Android/Java Similarities
Android uses Java syntax
Android uses similar APIs
Android, supports a relatively large subset of the Java Standard Edition 5.0 library
Java files on Android are compiled into .class files and then in dalvik executables(.dex)
java.io - File and stream I/Ojava.lang - Language & exceptionsupportjava.math - Big numbers, rounding, precisionjava.net - Network I/O, URLs, socketsjava.nio - File and channel I/Ojava.security - Authorization, certificates, public keysjava.sql - Database interfacesjava.text - Formatting, natural language, collation…
Java Essentials for Android
9
Android/Java Differences
Unlike Java VMs, which are stack machines, the Dalvik VM uses a register-based architecture
Dalvik does not align to Java SE nor Java ME class library profiles
Java is a programming language, while Android is a mobile phone platform
Java Essentials for Android
10
Android/Java Differences
Android does not use the Abstract Window Toolkit nor the Swing library. User Interface is built using View objects
Android layout behavior is encoded in the containers using XML files, unlike Java where Layout managers can be applied to any container widget
Android relies on a master AndroidManifest.xml file There is no Main class You need to define default activity here THIS IS A MANUAL METHOD
Java Essentials for Android
11
Android & EclipseSetup
Components
Development
12
Android Development Setup - 1
Your Development Computer Install Java Development Kit (JDK)
www.oracle.com/technetwork/Java/javase/downloads/index.html
Install Eclipse Classic version www.eclipse.org/downloads
Requirements: Windows, Mac, or Linux
developer.android.com/sdk/requirements.html
Java Essentials for Android
13
JDK
www.oracle.com/technetwork/Java/javase/downloads/index.html
14
Eclipse
www.eclipse.org/downloads
15
Android Development Setup - 2 Downloading the SDK Starter Package
Install Android SDK http://developer.android.com/sdk/index.html
16
Android SDK Manager
17
Android Development Setup – 3a
ADT Plugin for Eclipse Start Eclipse Select Help > Install New Software.... Click Add, in the top-right corner
In the Add Repository dialog that appears, enter "ADT Plugin" for the Name Location:
https://dl-ssl.google.com/android/eclipse/
Click OK.
Java Essentials for Android
18
Android Development Setup – 3b
ADT Plugin for Eclipse In the Available Software dialog, select the
checkbox next to Developer Tools and click Next. In the next window, you'll see a list of the tools to
be downloaded. Click Next. Read and accept the license agreements, then
click Finish.
When the installation completes, Restart Eclipse!
Java Essentials for Android
19
Android Development Setup – 3c
Select Window > Preferences...
Select Android from the left panel You may see a dialog asking whether you want to send
usage statistics to Google. If so, make your choice and click Proceed. You cannot continue with this procedure until you click Proceed.
For the SDK Location in the main panel, click Browse... & locate your downloaded SDK directory
Click Apply, then OK
http://developer.android.com/sdk/eclipse-adt.html#installing
Java Essentials for Android
20
Android Development Tools (ADT)
The Android SDK includes several tools & utilities to help you create, test, & debug your projects
ADT plug-in conveniently incorporates most of these tools into the Eclipse IDE, where you can access them from the DDMS perspective
Java Essentials for Android
21
ADT Inventory
The Android Emulator
Dalvik Debug Monitoring Service (DDMS)
Android Asset Packaging Tool (AAPT)
Android Debug Bridge (ADB)
Java Essentials for Android
22
ADT Inventory-2
The following additional tools are also available:
SQLite3 A database tool
Traceview Graphical analysis tool
MkSDCard
dx: java bytecode to Dalvik executable
activityCreator Script
Java Essentials for Android
23
Android SDK
android.jar
Documentation
Samples directory
Tools directory
usb_driver
Java Essentials for Android
• Eclipse Navigation
• 24
• Package Explorer
• Code Editor• Outline View
• Eclipse Tools-DDMS
• 25
Dalvik Debug Monitor Service
Java Essentials for Android
26
Android Emulator
Create an Android Virtual Device
Run it!
Java Essentials for Android
27
Android Architecture
Applications
Application framework
Libraries
Android Runtime (Dalvik VM)
Linux 2.6 Kernel
28
29
Android Layers
Linux kernel provides drivers for the Android hardware, networking, file system access & inter-process-communication
Libraries are mostly written in C or C++
Core Libraries are the core development kit including utility, i.o. etc
Dalvik Virtual Machine is an optimized Java VM
Application Framework is the API to developers
Applications are user facing programs
Java Essentials for Android
30
Android Applications
• Each application runs in its own process, gets unique identifier & runs its own instance of Dalvik VM
This way the processes are isolated & crash of one application does not bring down the whole system!
Java Essentials for Android
31
Android Programming
System Level – modifying the Android system code & adapting it to various hardware platforms. It also involves creating additional services & features in the android system itself. C. C++
Application level – creating software products & services which sits on top of the Android software stack & interacts with the hardware through the underlying Android platform. Java.
Java Essentials for Android
32
Application Development Basics
Activity Presents visual interface to the user Each activity has a separate window to draw the visual component but if required it can
use more than one window also
Services runs in the background and carries out some
background process while the other visual component s are running in the foreground
Java Essentials for Android
33
Application Development Basics-2
Broadcast receivers responsible for receiving and reacting to broadcasted
messages
Content providers This provides specific set of data from one application to
other applications. Used in conjunction with Content resolver which provide methods for inter process communication
Widgets These are programs anchored to the home screen
providing information updated fairly frequently
Android ActivitiesEach Android application must designate a default activity within the Android manifest file
35
36
Android Activity ClassThe Activity base class defines a series of events that governs the life cycle of an
activity:
onCreate() — Called when the activity is first created
onStart() — Called when the activity becomes visible to the user
onResume() —when the activity starts interacting with the user
onPause() —current activity is being paused & the previous activity is being resumed
onStop() —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() —when the activity has been stopped & is restarting
37
Android Activity Class (2)
public void onStart(){super.onStart();Log.d(tag, “In the onStart() event”);}
public void onRestart(){super.onRestart();Log.d(tag, “In the onRestart() event”);}
38
Android Activities To create an activity, you create a Java class that
extends the Activity base class:
package com.example.Activities;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
39
Android Activities-2
Your activity class would then load its UI component using the XML file defined in your res/layout folder. In this example, you would load the UI from the main.xml file:setContentView(R.layout.main);
Every activity you have in your application must be declared in your AndroidManifest.xml file
40
Android Activities (3)<?xml version=”1.0” encoding=”utf-8”?><manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.Activities” android:versionCode=”1” android:versionName=”1.0”> <application android:icon=”@drawable/icon”
android:label=”@string/app_name”><activity android:name=”.MainActivity”
android:label=”@string/app_name”><intent-filter><action android:name=”android.intent.action.MAIN” /><categoryandroid:name=”android.intent.category.LAUNCHER” /></intent-filter>
</activity> </application> <uses-sdk android:minSdkVersion=”9” /></manifest>
41
Android Layouts
An Android layout is a class that handles arranging the way its children appear on the screen Anything that is a View (or inherits from View) can be a
child of a layout
All of the layouts inherit from ViewGroup (which inherits from View) so you can nest layouts You could also create your own custom layout by making
a class that inherits from ViewGroup
42
The Android Layouts are:
AbsoluteLayout
FrameLayout
LinearLayout
RelativeLayout
TableLayout
Java Essentials for Android
43
Android Resources
Google Samples
F-droid.org
sourceforge.net
Java Essentials for Android
44
Example: Timesheet
Timesheet is an application designed primarily for contractors and freelancers to track the time spent on different tasks. http://tastycactus.com/projects/timesheet/
f-droid.org/repository/browse/?fdfilter=timesheet&fdid=com.tastycactus.timesheetplay.google.com/store/apps/details?id=com.tastycactus.timesheet
Java Essentials for Android
45
Java Essentials for Android
Q& A