Android Programming Tutorial

3y ago
94 Views
12 Downloads
1.46 MB
20 Pages
Last View : 1d ago
Last Download : 3m ago
Upload by : Victor Nelms
Transcription

Android Programming TutorialRong Zheng

Outline What is Android OS Setup your development environment GUI Layouts Activity life cycle Event handling Tasks Intent and broadcast receiver Resource

What is Android Linux-based OS Dalvik virtualmachine runningdex-code translatedfrom Java

Setup

What you need JDK 6 IDE ADT (Android Development Tool) bundle or Eclipse ADT plug-in Android SDKor Android studio Download earlier SDK versions using SDK manager ifneeded

Android Virtual Device (AVD) Android emulator allowsdevelopment w/o physicaldevice Tend to be slow when launchedthe first time Can emulate network, cameraand storage No support for WiFi, Bluetooth,most hardware sensors Possible alternatives: Genymotion (previouslyAndroVM), Manymo, Demo: create a new AVD

Android App Essentials Layout View objects: UI widgets such as buttons, text box etc. Positioning view objects on the screen View group: invisible view containers that defines how thechild views are laid out Activity Implements the real logic behind the application There could be multiple activities

Activity life cycle Screen rotation Application paused,stopped and restarted onCreate() called Press home button Activity paused, onPause(), onStop() called;onRestart() called whenrestarted Press back button Activity destroyed,onPause(), onStop,onDestroy()

Example: Network tester Display the network configuration Ping google.com Download a file from a fixed URL and determine the downloading speed

Step 1: Create an Android Project New New Android Application

Step 2: Lay out UI RelativeLayout xmlns:android 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 ".MainActivity" LinearLayoutandroid:layout width "match parent"android:layout height "match parent"android:orientation "vertical" Buttonandroid:id "@ id/netinfo button"android:layout width "match parent"android:layout height "wrap content"android:text "Show Network Configuration" / Buttonandroid:id "@ id/ping button"android:layout width "match parent"android:layout height "wrap content"android:text "Ping" / Buttonandroid:id "@ id/fd button"android:layout width "match parent"android:layout height "wrap content"android:text "File Download" / TextViewandroid:id "@ id/text display"android:layout width "match parent"android:layout height "wrap content"android:maxLines "100"android:padding "24dp"android:scrollbars "vertical" / /LinearLayout ProgressBarandroid:id "@ id/test progressBar"style layout width "match parent"android:layout height "wrap content"android:layout alignParentBottom "true"android:layout margin "10dp"android:visibility "invisible"/ /RelativeLayout

Step 3: From Layout to View Objects setContentView(R.layout.activity main) inflates a layoutand put on screen R.layout.activity main is a resource id @ id/resource id automatically creates the resource id Wire up widgets Get the references public View findViewById( int id) Set listeners

AsyncTask Network operations typically take time to complete AsyncTask allows operations running in the background andpublishing the results on the UI thread Do not block the UI thread! Do not access the Android UI toolkits from outside the UI thread Implement a class that extends AsyncTask Param, Progress,Result Params, the type of the parameters sent to the task uponexecution. Progress, the type of the progress units published during thebackground computation. Result, the type of the result of the background computation

AsyncTask (cont) doInBackground(Void. params) What to do in the background protected void onProgressUpdate(Void. progress) Run in the UI thread Invoked by publishProgress in the doInBackground protected void onPostExecute(Void result) Run in the UI thread protected void onPreExecute() Set up the taskExample code

Little tricks Can execute shell commands from Android app Runtime.getRuntime().exec(Cmd) Disable screen rotation activity android:name roid:label "@string/app name"android:screenOrientation "portrait"

Little tricks (cont’d) User handler to cancel an AsyncTask after some time public final boolean postDelayed (Runnable r, longdelayMillis)Handler handler new Handler();handler.postDelayed(new Runnable() {@Override public void run() {if (downloader.getStatus() }, 60000); Use toast for notificationToast.makeText(MainActivity.this, "Opps.", Toast.LENGTH SHORT).show();

Intent and broadcast receiver Intent is a mechanism in Android to allow late binding ofcomponents within and across applications Message passingIntentBroadcast intentYour applicationIntent(DO SOMETHING)Android OS(any app)Intent(DO SOMETHING)

Broadcast receiver Allows to register for system wide or application events ACTION BATTERY LOW, ACTION HEADSET PLUG,ACTION SCREEN ON, ACTION TIMEZONE CHANGED,WifiManager.SCAN RESULTS AVAILABLE ACTION, etc1. Step1: extend a broadcast receiver class and overrideonReceive(Context c, Intent intent) method2. Step 2: register the receiver(BroadcastReceiver receiver,IntentFilter filter)3. Step 3: change AndroidManifest.xml to add thepermission

Exampleif (mReceiverWifi null)mReceiverWifi new WifiReceiver();registerReceiver(mReceiverWifi, new IntentFilter(WifiManager.NETWORK STATE CHANGED ACTION));description of Intent values tobe matchedprivate class WifiReceiver extends BroadcastReceiver {public void onReceive(Context c, Intent intent) {NetworkInfo info oString());};}

Resource ADT bundlehttp://developer.android.com/sdk/index.html ADT Eclipse pse-adt.html Android .html

ADT (Android Development Tool) bundle or ! Eclipse ADT plug-in Android SDK or ! Android studio ! Download earlier SDK versions using SDK manager if needed . Android Virtual Device (AVD) ! Android emulator allows . Android App Essentials ! Layout ! View objects: UI widgets such as buttons, text box etc. .

Related Documents:

An Android Studio SQLite Database Tutorial Previous Table of Contents Next An Android Studio TableLayout and TableRow Tutorial Understanding Android Content Providers in Android Studio eBookFrenzy.com Purchase the fully updated Android 6 Edition of this Android Studio Development Essentials publication in eBook ( 9.99) or Print ( 38.99) format

Android Studio IDE Android SDK tool Latest Android API Platform - Android 6.0 (Marshmallow) Latest Android API emulator system image - Android 6.0 Android Studio is multi-platform Windows, MAC, Linux Advanced GUI preview panel See what your app looks like in different devices Development environment Android Studio 9

Android Development Tools ADT A plug-in for Eclipse (see Eclipse) to develop Android applications. Android Operating system for smartphones. Android Market The Android distribution service of mobile applications. Android Lifecycle A model Android uses to handle the lifecycle of an activity in applications.

Dial91 Android Edition User Guide 1 About Dial91 Android Edition Dial91 Android Edition is a SIP- based phone for an Android phone. With Dial91 Android Edition (Dial91), you can use the Wi-Fi internet connection on your Android phone to make and receive calls without using your mobile

ANDROID QUICK START GUIDE WELCOME TO ANDROID 1 1 Welcome to Android About Android 5.0, Lollipop Android 5.0, Lollipop is the latest version of Android, the oper-ating system that powers not just phones and tablets, but also wearables, TVs, and even cars. Android 5.0 features a bold and bright new design, 3D graphics

Navigate to https://developer.android.com/studio/index.html and download Android Studio for your appropriate OS. The Android SDK should be included with Android Studio. Make sure you do not choose an Android Studio installation that excludes the Android SDK. Standard download option for Windows OS (above). Alternative

2010 - May: Android 2.2 / Froyo 2010 - Dec: Android 2.3 / Gingerbread 2011 - Jan : Android 3.0 / Honeycomb - Tablet-optimized 2011 - May: Android 3.1 - USB host support 2011 - Nov: Android 4.0 / Ice-Cream Sandwich - merge Gingerbread and Honeycomb 2012 - Jun: Android 4.1 / Jelly Bean - Platform Optimization

1963 Ford Fairlane Wiring Diagram.pdf would be hard to argue against that 49ers' Jordan Reed, Dee Ford could both be placed on IR 49ers beat Reed has knee sprain; Ford might go on IR By Eric Branch The 49ers might be without two former Pro Bowl players for the foreseeable future. In addition, Shanahan said the team would decide in the