1 / 20

Android Programming

Creating an Android Application by Abhijit Patil. Android Programming. Android Programming. Components of Android Application Activity Intent/Broadcast Receiver Services Content Provider. Android Programming. Getting Started – Preliminaries Installing Eclipse Galileo with JRE 1.6

deron
Télécharger la présentation

Android Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Creating an Android Application by Abhijit Patil Android Programming

  2. Android Programming • Components of Android Application • Activity • Intent/Broadcast Receiver • Services • Content Provider

  3. Android Programming • Getting Started – Preliminaries • Installing Eclipse Galileo with JRE 1.6 • Installing Android SDK. • Creating Android Virtual Device (AVD)

  4. Getting Started • Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT) • ADT extends the capabilities of Eclipse to let you quickly set up new Android projects, create an application UI, add components based on the Android Framework API, debug your applications • In general, using Eclipse with ADT is a highly recommended approach to Android development and is the fastest way to get started. • To install and update the ADT Plugin, you can take advantage of the Eclipse remote update feature. By setting up a remote update site, you can easily download, install, and check for ADT updates. Alternatively, you can download the latest ADT to your development computer as a local site archive. The sections below provide instructions for both methods.

  5. Creating first Android Project - Components Project Name - This is the Eclipse Project name — the name of the directory that will contain the project files. • Application Name - This is the human-readable title for your application — the name that will appear on the Android device. • Package Name - This is the package namespace (following the same rules as for packages in the Java programming language) that you want all your source code to reside under. This also sets the package name under which the stub Activity will be generated. • Create Activity - This is the name for the class stub that will be generated by the plugin. This will be asubclass of Android's Activity class.

  6. Android Programming • Creating first Android Project • Select File -> New -> Other -> Android -> Android Project and create the Android project with your package name. • Enter application name as “First Android App” and package name as "mu.abhi.android.first" • Press 'Finish'.

  7. Android Programming • Android Project Directory Structure. Java Files Resources

  8. AndroidManifest.xml • Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory. The manifest presents essential information about the application to the Android system • * It names the Java package for the application. The package name serves as a unique identifier for the application. • * It describes the components of the application — the activities, services, broadcast receivers, and content providers that the application is composed of. • * It determines which processes will host application components. • * It declares which permissions the application must have in order to access protected parts of the API and interact with other applications. • * It also declares the permissions that others are required to have in order to interact with the application's components.

  9. Android Programming • Adding UI Elements – • Using XML • Double-click on main.xml • From Views panel add 'EditText' and 'Buttons'. • R.java will contain all these new elements.

  10. Android Programming • Setting Background Color • Double click on 'Strings.xml' • Click 'Add' - select color and put "white" as the name and "#FFFFFF" as the value. • Go back to 'Main.xml' and in Property view add '@color/white' in Background field.

  11. Android Programming • Write code in Hello.java • This is the class who does all the work. • Uses packages, android.app.Activity; android.os.Bundle; android.view.View; android.widget.EditText; • Uses Listener, myClickHandler

  12. Write code in Hello.java • Package android.app.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). • * 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. • To be of use with Context.startActivity(), all activity classes must have a corresponding <activity> declaration in their package's AndroidManifest.xml.

  13. Write code in Hello.java • Package android.view.View; • This class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties.

  14. Write code in Hello.java • Package android.widget.EditText; • EditText is a thin veneer over TextView that configures itself to be editable. • XML attributes • EditText Attributes, TextView Attributes, View Attributes

  15. Android Programming • Attach Java Methods to Buttons • Click on 'Main.xml' and select the particular Button. • In property view; tie the corresponding Java Method to 'On Click'

  16. Android Programming • Running the Application • From Eclipse: Right click on the project and click Run-As>Android Application. • From Phone: Click on the Menu button. Application will be displayed in the menu. Click on it to run. The Eclipse ADT will automatically create a new run configuration for your project and the Android Emulator will automatically launch. Once the emulator is booted up, your application will appear after a moment.

  17. Permissions • A central design point of the Android security architecture is that no application, by default, has permission to perform any operations that would adversely impact other applications, the operating system, or the user. This includes reading or writing the user's private data (such as contacts or e-mails), reading or writing another application's files, performing network access, keeping the device awake, etc. • An application's process is a secure sandbox. It can't disrupt other applications, except by explicitly declaring the permissions it needs for additional capabilities not provided by the basic sandbox. These permissions it requests can be handled by the operating in various ways,typically by automatically allowing or disallowing based on certificates orby prompting the user. The permissions required by an application are declared statically in that application, so they can be known up-front at install time and will not change after that.

  18. Permissions • Creator can define access right to Application • Application permissions can be changed in "AndroidManifest.xml" • For Example, "android.permission.WRITE_SETTINGS"

  19. Android Programming • Debugging • Tools for debugging in Android • Logcat • Traceview • Dalvik Debug Monitor Server (DDMS)

  20. Android Programming • References • Android Developer Site http://developer.android.com/index.html • Hello, Android: Introducing Google's Mobile Development Platformby Ed Burnette - Pragmatic Bookshelf; 2nd edition (2009) • Android Tutorials http://www.vidyut.com/sunit/android/

More Related