Presentation is loading. Please wait.

Presentation is loading. Please wait.

INTRODUCTION TO ANDROID. Slide 2 Introduction I take a top-down approach to describing an application’s anatomy.

Similar presentations


Presentation on theme: "INTRODUCTION TO ANDROID. Slide 2 Introduction I take a top-down approach to describing an application’s anatomy."— Presentation transcript:

1 INTRODUCTION TO ANDROID

2 Slide 2 Introduction I take a top-down approach to describing an application’s anatomy

3 Slide 3 Android Manifest (Description) It contains the information necessary to compile and run an Android application It’s an XML document that uses the Android namespace It defines the SDK versions It defines the activity(s) and startup activity

4 Slide 4 Android Manifest (Illustration) The purpose of AndroidManifest.xml is similar to web.config or app.config Simply put, it describes the application

5 Slide 5 Android Manifest (Editing) Eclipse supports a WYSISYG editor

6 Slide 6 Resources (Introduction) Android uses resources to store data such as strings and window sizes layouts (windows) Icons And more All are represented as XML documents All appear in the folder res

7 Slide 7 Resources (Folders) These folder names are significant res/drawable-xxx contains the icons used by an application res/menu contains the application’s menu(s) res/values/strings.xml contains string resources res/values/dimens.xml contains sizes res/values/styles contains themes

8 Slide 8 The res/Menu Folder It defines an application’s menu(s) element contains elements Again, Eclipse provides a WYSIWYG editor More later

9 Slide 9 The res/values Fodler The folder values\strings.xml contains the application’s textual content

10 Slide 10 String Resources (res/values/Strings.xml) Strings literals are stored in the file strings.xml Root element is elements contain the literal strings name attribute contains the id Element’s value contains the string’s value

11 Slide 11 Strings.xml And we reference those strings from the layout.xml

12 Slide 12 Dimens.xml It contains default screen values element contains a dimension name attribute contains the key Element content contains the value

13 Slide 13 Resource Files Android R.java is an auto-generated file by AAPT (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory If you create any component in the activity_main.xml file, the id for the corresponding component is automatically created in this file The id can be used in the activity source file to perform any action on the component

14 Slide 14 Resource File (Example)

15 Slide 15 Activities (Introduction) An Activity has a single screen with a UI Program logic is wired to a screen in a structured way (MVC) A program is initiated by running the default activity (Rather than main in a Java program) An activity is executed via predefined callbacks These are just procedures called by the Android infrastructure Most programs will have several activities

16 Slide 16 Activities (Parts) And activity has two parts One or more layouts that depict the screen A code file (Java)

17 Slide 17 Activity (Layout) Each activity appears as an XML file in the res/layout folder It defines layout of the screen and the widgets appearing on the screen

18 Slide 18 Activity (Layout) (Example) x

19 Slide 19 Application Components (Activities) (2) An activity is a class that derives from Activity Then we must override a couple of base class methods onCreate() And several others

20 Slide 20 Application Components (Activities) ( onCreate ) @Override indicates that we are overriding a base class method It’s an informative annotation Annotations are used to control compiler behavior Similar to.NET attributes

21 Slide 21 Application Components (Activities) ( onCreate ) super.onCreate calls the base class method super is roughly equivalent MyBase in VB It typically appears as the first statement in the method

22 Slide 22 Application Components (Activities) ( onCreate ) setContentView takes one argument – the resource id corresponding to the activity It associates a particular view with the activity The resource is always named R layout is the layout that you want to use Followed by the resource id of the layout

23 Slide 23

24 Slide 24 Creating a First Project Click File, New, Project. Select Android Application Project

25 Slide 25 Define Application Parameters (1) Don’t use an old Minimum Required SDK

26 Slide 26 Define Application Parameters (1) The Application Name appears in the store when deployed The Project Name is only relevant to Eclipse The Package Name contains a reverse domain name It must be unique and must not be changed – this is how versioning is performed

27 Slide 27 Define Application Parameters (2) Minimum Required SDK contains the minimum SDK version on which the application will run Target SDK contains the desired SDK version on which the application will run Compile with contains the SDK version that will be used to compile the application Theme defines basic UI characteristics

28 Slide 28 Configure Project Create activity

29 Slide 29 Configure Icons Configuring the icons Just use the defaults

30 Slide 30 Create Blank Activity Create the default activity This gives you a blank screen (form) (Blank Activity)

31 Slide 31 Name the Activity and Layout Choose the default values

32 Slide 32 Application Anatomy (1) The file MainActivity.java contains the java code for the application’s activity (screen) Default methods are created too (onCreate, …)

33 Slide 33 Application Anatomy (4) The file activity_main.xml contains the XML code that describes the user interface layout

34 Slide 34 Setting up the Emulator (1) We can run programs via an emulator or directly attached to a physical device Using windows, you might need the driver from the device manufacturer

35 Slide 35 Setting up the Emulator (2) Click Window, Android Device Manager Click Create to create the new device I suggest the following settings

36 Slide 36 Setting up the Emulator (3) Under Windows set the memory to no more than 512MB

37 Slide 37 Setting up the Emulator (3)

38 Slide 38 Starting the Emulator Set the display characteristics Note that it takes a while to start the emulator

39 Slide 39 Running Hello World The emulator should start and be rendered Again, it takes a while to start

40 Slide 40 Running Hello World (5) Now run the application

41 Slide 41 Guidelines for Running on a Native Host (1) First, plug the device in If running Windows, you will likely need a device driver

42 Slide 42 References http://developer.android.com/tools/extras/oe m-usb.html http://developer.android.com/tools/extras/oe m-usb.html


Download ppt "INTRODUCTION TO ANDROID. Slide 2 Introduction I take a top-down approach to describing an application’s anatomy."

Similar presentations


Ads by Google