Upload
rudolph-ray
View
219
Download
0
Embed Size (px)
Citation preview
INTERNATIONAL SUMMER ACADEMIC COURSE
UNIVESITY OF NIS
ISAC – Android programming
ISAC – Android programming
Introductions into Android programming• SDK (Sowtware developement kit)• DVM(Dalvik Virtual Machine)• JAVA API• Eclipse
Android App Fundamentals The process of creating an android application Android SDK configuration Creating a new virtual device
ISAC – Android programming
Setup
Set up your developement environment
Set up AVDs and devices for testing
Install the Android SDK, Android Developement Tools and Android platforms
Create Android Virtual Devices and connect hardware devices for testing
Developement Create your application
Create an Android project with your source code, resources and manifest file
ISAC – Android programming
Debugging and testing
Build and run your application
Debugg your application
Build and run your application in debug mode
Debug your application using the Android debugging and logging tools
Test your application
Test your application using emulator or real devices
ISAC – Android programming
Publishing
Prepare your application for release
Debugg your application
Configure, build and test your application in release mode
Publicize, sell and distribute your application to users
Android SDK Configuring Android SDK manager Creating virtual devices Getting to know the environment Creating a new Android project and a “Hello world”
application
ISAC – Android programming
ISAC – Android programming
What is an activity?LayoutsManifestXMLR class
ISAC – Android programming
Activity
The basis of android applicationsA single Activity defines a single viewable
screen the actions, not the layout
Can have multiple per applicationEach is a separate entityThey have a structured life cycle
Different events in their life happen either via the user touching buttons or programmatically
ISAC – Android programming
Life cycle of an activity
ISAC – Android programming
Project components
src – your source codegen – auto-generated code (usually just R.java)Included librariesResources
Drawables (like .png images) Layouts Values (like strings)
Manifest file
ISAC – Android programming
XML – Extensible Markup Language
Used to define some of the resources Layouts (UI) Strings
Manifest file Shouldn’t usually have to edit it directly, Eclipse can do that for you Preferred way of creating UIs
Separates the description of the layout from any actual code that controls it
Can easily take a UI from one platform to another
ISAC – Android programming
R class
Auto-generated: you shouldn’t edit itContains IDs of the project resourcesEnforces good software engineeringUse findViewById and Resources object to get
access to the resources Ex. Button b = (Button)findViewById(R.id.button1) Ex. getResources().getString(R.string.hello));
ISAC – Android programming
Mafinest file
Contains characteristics about your application When have more than one Activity in app, NEED to specify it in
manifest file Go to graphical view of the manifest file Add an Activity in the bottom right Browse for the name of the activity
Need to specify Services and other components too Also important to define permissions and external libraries, like
Google Maps API
ISAC – Android programming
UI, layouts and components used in Android apps
Layouts
Eclipse has a great UI creator Generates the XML for you
Composed of View objectsCan be specified for portrait and landscape mode
Use same file name, so can make completely different UIs for the orientations without modifying any code
Types of layouts: Linear, Relative, Frame...
ISAC – Android programming
UI, layouts and components used in Android apps
Layouts
Eclipse has a great UI creator Generates the XML for you
Composed of View objectsCan be specified for portrait and landscape mode
Use same file name, so can make completely different UIs for the orientations without modifying any code
Types of layouts: Linear, Relative, Frame...
ISAC – Android programming
1. Intents and intent filter1.1. What are intents?
1.2. Starting activities
ISAC – Android programming
The following code demonstrates how you can start
another activity via an intent.
# Start the activity connect to the # specified class
Intent i = new Intent(this, ActivityTwo.class); startActivity(i);
2. Intents types2.1. Different types of intents2.2. Explicit IntentsExplicit intents explicitly define the component which
should be called by the Android system, by using the Java class as identifier.
2.3. Implicit IntentsImplicit intents specify the action which should be
performed and optionally data which provides content for the action.
3. Data transfer between activities 3.1. Data transfer to the target
component
Bundle extras = getIntent().getExtras(); if (extras == null) { return; } // get data via the key String value1 = extras.getString(Intent.EXTRA_TEXT); if (value1 != null) { // do something with the data }
3.2. Example: Using the share intent
// this runs, for example, after a button clickIntent intent = new Intent(Intent.ACTION_SEND);intent.setType("text/plain"); intent.putExtra(android.content.Intent.EXTRA_TEXT, "News for you!"); startActivity(intent);
3.3. Retrieving result data from a sub-activity