Download presentation
Presentation is loading. Please wait.
1
Android Application Development 1 6 May 2018
S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 1
2
What is Android? An open source Linux-based operating system intended for mobile computing platforms Includes a Java API for developing applications It is not a device or product 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 2
3
6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 3
4
What Skills Will Students Learn?
Reinforce the basics: OOP, decomposition, etc. Separation of UI design and functionality XML and resource files Events and Listeners Callback methods Threads 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 4
5
Android vs. iPhone Java vs. Objective-C
Direct install vs. Marketplace vs. App Store Open source? 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 5
6
What Should Students Already Know?
Java! inheritance, method overriding interfaces, casting exceptions debugging reading API documentation Eclipse easy to pick up quickly, though 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 6
7
Do I Need Phones? The emulator that is part of the Android toolset for Eclipse is quite good (though a bit slow) You may be able to get free “developer phones” from Google 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 7
8
Online Resources developer.android.com
code.google.com/p/apps-for-android/ stackoverflow.com videos from Google I/O conferences 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 8
9
Concepts: activity, service, broadcast receiver, content provider,
Understand applications and their components Concepts: activity, service, broadcast receiver, content provider, intent, AndroidManifest 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID
10
Applications Written in Java (it’s possible to write native code – will not cover that here) Good separation (and corresponding security) from other applications: Each application runs in its own process Each process has its own separate VM Each application is assigned a unique Linux user ID – by default files of that application are only visible to that application (can be explicitly exported) 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID
11
Application Components
Activities – visual user interface focused on a single thing a user can do Services – no visual interface – they run in the background Broadcast Receivers – receive and react to broadcast announcements Content Providers – allow data exchange between applications 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID
12
Activities Basic component of most applications
Most applications have several activities that start each other as needed Each is implemented as a subclass of the base Activity class 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID
13
Activities – The View Each activity has a default window to draw in (although it may prompt for dialogs or notifications) The content of the window is a view or a group of views (derived from View or ViewGroup) Example of views: buttons, text fields, scroll bars, menu items, check boxes, etc. View(Group) made visible via Activity.setContentView() method. 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID
14
Services Does not have a visual interface
Runs in the background indefinitely Examples Network Downloads Playing Music TCP/UDP Server You can bind to a an existing service and control its operation 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID
15
Broadcast Receivers Receive and react to broadcast announcements
Extend the class BroadcastReceiver Examples of broadcasts: Low battery, power connected, shutdown, timezone changed, etc. Other applications can initiate broadcasts 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID
16
Content Providers Makes some of the application data available to other applications It’s the only way to transfer data between applications in Android (no shared files, shared memory, pipes, etc.) Extends the class ContentProvider; Other applications use a ContentResolver object to access the data provided via a ContentProvider 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID
17
Intents An intent is an Intent object with a message content.
Activities, services and broadcast receivers are started by intents. ContentProviders are started by ContentResolvers: An activity is started by Context.startActivity(Intent intent) or Activity.startActivityForResult(Intent intent, int RequestCode) A service is started by Context.startService(Intent service) An application can initiate a broadcast by using an Intent in any of Context.sendBroadcast(Intent intent), Context.sendOrderedBroadcast(), and Context.sendStickyBroadcast() 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID
18
Shutting down components
Activities Can terminate itself via finish(); Can terminate other activities it started via finishActivity(); Services Can terminate via stopSelf(); or Context.stopService(); Content Providers Are only active when responding to ContentResolvers Broadcast Receivers Are only active when responding to broadcasts 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID
19
Android Manifest Its main purpose in life is to declare the components to the system: <?xml version="1.0" encoding="utf-8"?> <manifest > <application > <activity android:name="com.example.project.FreneticActivity" > </activity> </application> </manifest> 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID
20
Intent Filters Declare Intents handled by the current application (in the AndroidManifest): <?xml version="1.0" encoding="utf-8"?> <manifest > <application > <activity android:name="com.example.project.FreneticActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter > <action android:name="com.example.project.BOUNCE" /> <data android:mimeType="image/jpeg" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> </manifest> Shows in the Launcher and is the main activity to start Handles JPEG images in some way 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID
21
“Hello, Android” 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 21
22
Creating Your First(?) Android App
Set up your development environment Create a new Android project in Eclipse Run it in the emulator Hilarity ensues 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 22
23
1. Set Up Your Android Environment
Install Eclipse Install Android SDK (Android libraries) Install ADT plugin (Android development tools) Create AVD (Android virtual device) We’ve already done this for you!! 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 23
24
2. Create an Android Project in Eclipse
File → New → Project Select “Android Project” Fill in Project details... 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 24
25
Directory name Android version Java package Name that appears
on device Class to automatically create 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 25
26
3. Run the Android Application
Run → Run (or click the “Run” button) Select “Android Application” The emulator may take a few minutes to start, so be patient! You don't need to restart the emulator when you have a new version of your application 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 26
27
6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 27
28
Source code Auto-generated code String constants UI layout
Configuration 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 28
29
HelloAndroid.java 1 public class HelloAndroid extends Activity {
2 /** Called when the activity is first created. */ 3 4 public void onCreate(Bundle savedInstanceState) 5 { 6 super.onCreate(savedInstanceState); 7 setContentView(R.layout.main); 8 } 9 } 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 29
30
main.xml 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout 3 xmlns:android=" 4 android:orientation="vertical" 5 android:layout_width="fill_parent" 6 android:layout_height="fill_parent" 7 > 8 <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" 11 " /> 13 </LinearLayout> 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 30
31
strings.xml 1 <?xml version="1.0" encoding="utf-8"?>
2 <resources> 3 <string name="hello">Hello World, HelloAndroid! 4 </string> 5 <string name="app_name">Hello, Android</string> 6 </resources> 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 31
32
AndroidManifest.xml 1 <?xml version="1.0" encoding="utf-8"?>
3 xmlns:android=" 4 package="edu.upenn.cis542" 5 android:versionCode="1" 6 android:versionName="1.0"> 7 <application 8 <activity android:name=".HelloAndroid" 10 <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> 18 </application> 19 </manifest> 6 May 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 32
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.