1 / 30

Building first android application

Building first android application. Dr. Razi Iqbal razi. iqbal @ leads .edu.pk. Create a new Android Application. Create a new Android Application. Application Name Name of the App / Project Project Name Used by Eclipse and should be unique within a workspace Package Name

eugene
Download Presentation

Building first android application

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. Building first android application Dr. Razi Iqbal razi.iqbal@leads.edu.pk

  2. Create a new Android Application

  3. Create a new Android Application • Application Name • Name of the App / Project • Project Name • Used by Eclipse and should be unique within a workspace • Package Name • It is collection of Classes. Should be same for the lifetime of the app • Should be like com.razi.helloWorld • Minimum SDK • Lowest SDK that app will support. • Will support more devices and less features • Target SDK • Highest SDK an app supports • Compile with • Compiles with Highest API level. • Theme • Base theme for the project

  4. Android Versions

  5. Create a new Android Application

  6. Hello World Android Application

  7. Hello World Android Application

  8. Creating Emulator

  9. Creating New Run Configuration • ADT automatically creates Run Configuration • If that doesn’t suit a developer, new run configurations can be built. • Used for Customized Configurations • Emulator • Project • Activity

  10. Creating New Run Configuration

  11. Hello World Console • Contains all the tasks performed for the Project • ADB is Android Debug Bridge

  12. Project Components (Package Explorer) • src • It is source folder of the project • Contains the Package • com.razi.helloworld • The package contains .java file • MainActivity.java • Built during the new project wizard • src folder can have more than one package • Sometimes apps use different user packages • For Example • One for Web Access • One for Creating GUI

  13. Project Components (Package Explorer) • assets • It contains all the assets of the project • Normally will contain • Databases • Dictionaries • Read data from the assets • Accessed with • streams of bytes • Converted into Objects • Using proper methods

  14. Project Components (Package Explorer) • bin • Contains files built by ADT during build process • It contains all important .apk file • .apk is Android Package File • It is like exe file for windows • It’s a binary • It contains everything needed by Android app

  15. Project Components (Package Explorer) • res • Contains all the resources for the app • Icons, Images etc • Menus • Layouts • Activity_main.xml • Layout of the Activity • values • Strings.xml

  16. Project Components (Package Explorer) • gen • Its ADT generated folder • Files in this folder should not be changed manually • It contains • BuildConfig.java • R.java • R.java class is used • To reference the resources of the project in res folder • Each member of res has a class in R.java and contains all the members in that class • Don’t worry about Hex values

  17. AndroidManifest.xml 1 2 3

  18. AndroidManifest.xml • Provides the package name which is a unique identifier • Provides the version code • It is an integer value • Next values should be greater than the previous values • It is used for updates • Google Play knows when to inform user about updates based on this code • Code is not visible to the user • Provides version name • It’s a string value • <major>.<minor>.<point> e.g. 2.1.2 • It is used to display it to user • It can be anything like Date e.g. 2010-06-28 1

  19. AndroidManifest.xml • Provides minimum SDK version • Use to run the apps on minimum OS • Normally should be minimum OS to support more devices • Provides Target SDK version • Maximum SDK version • SDK in which the app is built and tested • Should be latest SDK to support latest features 2

  20. AndroidManifest.xml • Provides Launcher Icon • Available in Drawable folder under res. • Provides App Label • Label for the application • The Label is stored in strings.xml file • Provides App Theme • Theme for the app • Available in styles.xml file • Provides Activity • There is one activity • Activity is handled by MainActivity.java in src folder • Label for the Activity is the same as app name under strings.xml 3

  21. strings.xml • Available under res  values • Contains strings for the project (app) • All strings should be in this xml file • Strings are in this file so that localization is easy • If in future the app is to be converted into some other language only strings in this file will be converted • It contains • Name (the name of the string e.g. app_name) • Value (the value of the string e.g. Hello World)

  22. activity_main.xml • xmlns: android and xmlns:tools are the namespaces • .MainActivity tells this layout is for MainActivity.java file • @dimen and @string are defined in R.java

  23. colors.xml • Add new XML file for colors in res  values • Name it colors.xml • Copy paste colors in the file • Save it • Use it like this • @color/Red android:textColor="@color/Red" To change the Font size android:textSize="40sp"

  24. Adding a Button • Add new Button by dragging and Dropping • Change Text to “Click Me!” • Placement will be relative to Text View • Check for R.java class • It will add a new button1 in id class • This is done after building the project

  25. MainActivity.java 1 2 3 4

  26. MainActivity.java • Package for current App • Developed during New Project Wizard • It contains the App • A Project can have Multiple Packages 1 • Using Android Available Packages • In order to use classes, we have to import Packages • Different packages are imported in this case • import android.os.Bundle; • import android.app.Activity; • import android.view.Menu; 2

  27. MainActivity.java • Inherit MainActivity from Activity Class • Our MainActivity class is subclass of Activity • Activity Class contains many methods • MainActivity can use these methods 3 • onCreate is a methods in Activity class • @Override is used to tell the compiler we are overriding the superclass method • App will compile without it also but better use it 4

  28. Change text on Button Click

  29. Anonymous Inner Class

  30. Updated Hello World Code

More Related