SlideShare une entreprise Scribd logo
1  sur  48
Télécharger pour lire hors ligne
Android Basics




- Bhaumik Shukla
Android Application Developer
@ STEALTH FLASH
Introduction to Android
• Android is a software stack for mobile
  devices that includes an operating system,
  middleware and key applications.
• The Android SDK provides the tools and
  APIs necessary to begin developing
  applications on the Android platform using
  the Java programming language.
Introduction to Android
• Android is an open-source platform developed
  under the Open Handset Alliance to enable
  faster development of mobile applications and
  provision of services to the user.
• Google is the leading company to develop and
  promote Android, however there are other
  companies as well who are involved in the
  development of Android. Some of these include
  T-Mobile, HTC, Qualcomm and others.
Features
• Application framework enabling reuse and replacement of
  components
• Dalvik virtual machine optimized for mobile devices
• Integrated browser based on the open source WebKit engine
• Optimized graphics powered by a custom 2D graphics library; 3D
  graphics based on the OpenGL ES 1.0 specification (hardware
  acceleration optional)
• SQLite for structured data storage
• Media support for common audio, video, and still image formats
  (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)
• GSM Telephony (hardware dependent)
• Bluetooth, EDGE, 3G, and WiFi (hardware dependent)
• Camera, GPS, compass, and accelerometer (hardware
  dependent)
• Rich development environment including a device emulator, tools
  for debugging, memory and performance profiling, and a plugin for
  the Eclipse IDE
Tools
• Emulator
  – Android applications may be
     run on a real device or on the
     Android Emulator, which ships
     with the Android SDK.

• ADB (Android Debug Bridge)
  – The ADB utility lets you connect to the phone itself
  and issue rudimentary shell commands, such as copying
  files to and from the device.
Architecture
Applications
• Android will ship with a set of core
  applications including an email client, SMS
  program, calendar, maps, browser,
  contacts, and others. All applications are
  written using the Java programming
  language.
Application Framework
• A rich and extensible set of Views that can be used to
  build an application, including lists, grids, text boxes,
  buttons, and even an embeddable web browser
• Content Providers that enable applications to access
  data from other applications (such as Contacts), or to
  share their own data
• A Resource Manager, providing access to non-code
  resources such as localized strings, graphics, and layout
  files
• A Notification Manager that enables all applications to
  display custom alerts in the status bar
• An Activity Manager that manages the lifecycle of
  applications and provides a common navigation
  backstack
Libraries
• System C library - a BSD-derived implementation of the standard C
  system library (libc), tuned for embedded Linux-based devices
• Media Libraries - based on PacketVideo's OpenCORE; the libraries
  support playback and recording of many popular audio and video
  formats, as well as static image files, including MPEG4, H.264, MP3,
  AAC, AMR, JPG, and PNG
• Surface Manager - manages access to the display subsystem and
  seamlessly composites 2D and 3D graphic layers from multiple
  applications
• LibWebCore - a modern web browser engine which powers both
  the Android browser and an embeddable web view
• SGL - the underlying 2D graphics engine
• 3D libraries - an implementation based on OpenGL ES 1.0 APIs;
  the libraries use either hardware 3D acceleration (where available)
  or the included, highly optimized 3D software rasterizer
• FreeType - bitmap and vector font rendering
• SQLite - a powerful and lightweight relational database engine
  available to all applications
Android Runtime
• Android includes a set of core libraries that provides
  most of the functionality available in the core libraries of
  the Java programming language.
• Every Android application runs in its own process, with
  its own instance of the Dalvik virtual machine. Dalvik has
  been written so that a device can run multiple VMs
  efficiently. The Dalvik VM executes files in the Dalvik
  Executable (.dex) format which is optimized for minimal
  memory footprint. The VM is register-based, and runs
  classes compiled by a Java language compiler that have
  been transformed into the .dex format by the included
  "dx" tool.
• The Dalvik VM relies on the Linux kernel for underlying
  functionality such as threading and low-level memory
  management.
Linux Kernel
• Android relies on Linux version 2.6 for core
  system services such as security, memory
  management, process management, network
  stack, and driver model. The kernel also acts as
  an abstraction layer between the hardware and
  the rest of the software stack.
Application Fundamentals
• Apps are written in Java
• Bundled by Android Asset Packaging Tool
• Every App runs its own Linux process
• Each process has it’s own Java Virtual
  Machine
• Each App is assigned a unique Linux user
  ID
• Apps can share the same user ID to see
  each other’s files
Application Fundamentals
• Android applications are written in the
  Java programming language. The
  Android SDK tools compile the
  code—along with any data and
  resource files—into an Android
  package, an archive file with an .apk
  suffix. All the code in a single .apk file
  is considered to be one application
  and is the file that Android-powered
  devices use to install the application.
Application Components
• Application components are the essential
  building blocks of an Android application. Each
  component is a different point through which the
  system can enter your application. Not all
  components are actual entry points for the user
  and some depend on each other, but each one
  exists as its own entity and plays a specific
  role—each one is a unique building block that
  helps define your application's overall behavior.
Application Components
• Activities
  – An activity represents a single screen with a user
    interface.
  – Present a visual user interface for one focused
    endeavor the user can undertake
  – Example: a list of menu items users can choose from,
    or anything.
Application Components
• Services
   – A service is a component that runs in the background to perform
     long-running operations or to perform work for remote
     processes.
   – A service does not provide a user interface. For example, a
     service might play music in the background while the user is in
     a different application, or it might fetch data over the network
     without blocking user interaction with an activity. Another
     component, such as an activity, can start the service and let it
     run or bind to it in order to interact with it.
Application Components
• Content providers
   – A content provider manages a shared set of
     application data. You can store the data in the file
     system, an SQLite database, on the web, or any other
     persistent storage location your application can
     access. Through the content provider, other
     applications can query or even modify the data (if the
     content provider allows it). For example, the Android
     system provides a content provider that manages the
     user's contact information. As such, any application
     with the proper permissions can query part of the
     content provider (such as ContactsContract.Data) to
     read and write information about a particular person.
Application Components
• Broadcast receivers
  – A broadcast receiver is a component that
    responds to system-wide broadcast
    announcements. Many broadcasts originate
    from the system—for example, a broadcast
    announcing that the screen has turned off, the
    battery is low, or a picture was captured.
  – Receive and react to broadcast
    announcements
  – Example: announcements that the time zone
    has changed
Application Components
• Three of the four component types—activities,
  services, and broadcast receivers—are activated
  by an asynchronous message called an intent.
• Intents bind individual components to each other
  at runtime (you can think of them as the
  messengers that request an action from other
  components), whether the component belongs
  to your application or another.
• An intent is created with an Intent object, which
  defines a message to activate either a specific
  component or a specific type of component—an
  intent can be either explicit or implicit,
  respectively.
Application Components
• There are separate methods for activiting each type of
  component:
• You can start an activity (or give it something new to do)
  by passing an Intent to startActivity() or
  startActivityForResult() (when you want the activity to
  return a result).
• You can start a service (or give new instructions to an
  ongoing service) by passing an Intent to startService().
  Or you can bind to the service by passing an Intent to
  bindService().
• You can initiate a broadcast by passing an Intent to
  methods like sendBroadcast(), sendOrderedBroadcast(),
  or sendStickyBroadcast().
• You can perform a query to a content provider by calling
  query() on a ContentResolver.
The Manifest File
•   Before the Android system can start an application component, the system
    must know that the component exists by reading the application's
    AndroidManifest.xml file (the "manifest" file). Your application must declare
    all its components in this file, which must be at the root of the application
    project directory.
•   The manifest does a number of things in addition to declaring the
    application's components, such as:
•   Identify any user permissions the application requires, such as Internet
    access or read-access to the user's contacts.
•   Declare the minimum API Level required by the application, based on which
    APIs the application uses.
•   Declare hardware and software features used or required by the application,
    such as a camera, bluetooth services, or a multitouch screen.
•   API libraries the application needs to be linked against (other than the
    Android framework APIs), such as the Google Maps library.
•   And more
The Manifest File
The primary task of the manifest is to inform the system about the application's
   components. For example, a manifest file can declare an activity as follows:
-----------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
    <manifest ... >
       <application android:icon="@drawable/app_icon.png" ... >
           <activity android:name=".ExampleActivity"
                   android:label="@string/example_label" ... >
           </activity>
           ...
       </application>
    </manifest>
Application Resources
• An Android application is composed of more than just
  code—it requires resources that are separate from the
  source code, such as images, audio files, and anything
  relating to the visual presentation of the application.
• For example, you should define animations, menus,
  styles, colors, and the layout of activity user interfaces
  with XML files. Using application resources makes it
  easy to update various characteristics of your application
  without modifying code and—by providing sets of
  alternative resources—enables you to optimize your
  application for a variety of device configurations (such as
  different languages and screen sizes).
Activity
life cycle
Activity callbacks
• onCreate() Called when the activity is first created. This is
  where you should do all of your normal static set up — create views,
  bind data to lists, and so on. This method is passed a Bundle object
  containing the activity's previous state, if that state was captured
  (see Saving Activity State, later). Always followed by onStart().
• onRestart() Called after the activity has been stopped, just prior
  to it being started again. Always followed by onStart()

• onStart() Called just before the activity becomes visible to the
  user. Followed by onResume() if the activity comes to the
  foreground, or onStop() if it becomes hidden.

• onResume() Called just before the activity starts interacting
  with the user. At this point the activity is at the top of the activity
  stack, with user input going to it. Always followed by onPause().
Activity callbacks
• onPause() Called when the system is about to start resuming
  another activity. This method is typically used to commit unsaved
  changes to persistent data, stop animations and other things that
  may be consuming CPU, and so on. It should do whatever it does
  very quickly, because the next activity will not be resumed until it
  returns. Followed either by onResume() if the activity returns back to
  the front, or by onStop() if it becomes invisible to the user.

• onStop() Called when the activity is no longer visible to the
  user. This may happen because it is being destroyed, or because
  another activity (either an existing one or a new one) has been
  resumed and is covering it. Followed either by onRestart() if the
  activity is coming back to interact with the user, or by onDestroy() if
  this activity is going away.
Activity callbacks
• onDestroy() Called before the activity is destroyed.
  This is the final call that the activity will receive. It could
  be called either because the activity is finishing
  (someone called finish() on it), or because the system is
  temporarily destroying this instance of the activity to
  save space. You can distinguish between these two
  scenarios with the isFinishing() method.
Declaring Activity
• Declaring the activity in the manifest
• You must declare your activity in the manifest file in order for it to be
  accessible to the system. To declare your activity, open your
  manifest file and add an <activity> element as a child of the
  <application> element. For example:


   <manifest ... >
    <application ... >
        <activity android:name=".ExampleActivity" />
        ...
    </application ... >
    ...
   </manifest >
View Groups
• FrameLayout Layout that acts as a view frame to display a single
  object.
• Gallery A horizontal scrolling display of images, from a bound list.
• GridView Displays a scrolling grid of m columns and n rows.
• LinearLayout A layout that organizes its children into a single
  horizontal or vertical row. It creates a scrollbar if the length of the
  window exceeds the length of the screen.
• ListView Displays a scrolling single column list.
• RelativeLayout Enables you to specify the location of child objects
  relative to each other (child A to the left of child B) or to the parent
  (aligned to the top of the parent).
• ScrollView A vertically scrolling column of elements.
• etc..
View Groups
Write XML for UI design
•  Using Android's XML vocabulary, you can quickly design UI layouts and the
   screen elements they contain, in the same way you create web pages in
   HTML — with a series of nested elements.
sample main.xml
   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:orientation="vertical" >
     <TextView android:id="@+id/text"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Hello, I am a TextView" />
     <Button android:id="@+id/button"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Hello, I am a Button" />
   </LinearLayout>
Installation
• How to install & configure Android SDK
  and Eclipse
 http://developer.android.com/sdk/installing.html
Configure AVD
http://developer.android.com/guide/developing/devices/managing-avds.html
• Creating an AVD
• You can create as many AVDs as you would like to test on. It is
  recommended that you test your applications on all API levels higher
  than the target API level for your application.
• To create an AVD:
• Start the AVD Manager:
    – In Eclipse: select Window > Android SDK and AVD Manager, or click
      the Android SDK and AVD Manager icon in the Eclipse toolbar.
    – In other IDEs: Navigate to your SDK's tools/ directory and execute the
      android tool with no arguments.
• In the Virtual Devices panel, you'll see a list of existing AVDs. Click
  New to create a new AVD. The Create New AVD dialog appears.
Configure AVD
Start Developing on Android
First Android Project
•       Select File > New > Project.
•       Select Android > Android Project, and click Next.
•       Select the contents for the project:
    –      Enter a Project Name.
    –      Under Target, select an Android target to be used as the project's Build Target


    –        Under Properties, fill in all necessary fields.
           •    Enter an Application name.
           •    Enter a Package name.
           •    Select Create Activity (optional, of course, but common) and enter a name
                for your main Activity class.
           •    Enter a Min SDK Version
•       Click Finish.
•   Your Android project is now ready. It should be visible in the Package
    Explorer on the left. Open the HelloAndroid.java file, located inside
    HelloAndroid > src > com.example.helloandroid). It should look like this:
•
    package com.example.helloandroid;

    import android.app.Activity;
    import android.os.Bundle;

    public class HelloAndroid extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
      }
    }
res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/textview"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:text="@string/hello"/>

res/layout/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
   <string name="hello">Hello, Android! I am a string
resource!</string>
   <string name="app_name">Hello, Android</string>
</resources>
Handling UI Events
• On Android, there's more than one way to intercept the
  events from a user's interaction with your application.
  When considering events within your user interface, the
  approach is to capture the events from the specific View
  object that the user interacts with. The View class
  provides the means to do so.

• Event Listeners An event listener is an interface in the
  View class that contains a single callback method. These
  methods will be called by the Android framework when
  the View to which the listener has been registered is
  triggered by user interaction with the item in the UI.
Handling UI Events
• onClick() From View.OnClickListener.
• onLongClick() From View.OnLongClickListener.
• onFocusChange() From
  View.OnFocusChangeListener.
• onKey() From View.OnKeyListener.
• onTouch() From View.OnTouchListener.
• onCreateContextMenu() From
  View.OnCreateContextMenuListener.
How to write Click event
• The example below shows how to register an on-click listener for a Button.
// Create an anonymous implementation of OnClickListener

private OnClickListener mCorkyListener = new OnClickListener() {
       public void onClick(View v) {
         // do something when the button is clicked
       }
    };

   protected void onCreate(Bundle savedValues) {
     ...
     // Capture our button from layout
     Button button = (Button)findViewById(R.id.btn);
     // Register the onClick listener with the implementation above
     button.setOnClickListener(mCorkyListener);
     ...
   }
How to write Click event
•   You may also find it more convenient to implement OnClickListener as a
    part of your Activity. This will avoid the extra class load and object
    allocation. For example:

    public class ExampleActivity extends Activity implements OnClickListener {
      protected void onCreate(Bundle savedValues) {
         ...
         Button button = (Button)findViewById(R.id.btn);
         button.setOnClickListener(this);
      }

        // Implement the OnClickListener callback
        public void onClick(View v) {
          // do something when the button is clicked
        }
        ...
    }
Example
Button Click example counts the clicks.
• We need a to declare activity in AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test"
    android:versionCode="1"
    android:versionName="1.0“>
  <application android:icon="@drawable/icon" android:label="@string/app_name">
     <activity android:name=".test"
            android:label="@string/app_name">
       <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
     </activity>
  </application>
</manifest>
Example
Button Click example counts the clicks.
• We need a button in main.xml
<?xml version=”1.0″ encoding=”utf-8″?>
   <LinearLayout android:id=”@+id/linear1″
   android:layout_width=”fill_parent” android:layout_height=”fill_parent”
   xmlns:android=”http://schemas.android.com/apk/res/android”>
   <Button android:text=”ClickMe” android:id=”@+id/button1″
   android:layout_width=”wrap_content”
   android:layout_height=”wrap_content”></Button>
</LinearLayout>
Example
Button Click example counts the clicks.
Activity.Java
   package com.example.test;
   import android.app.Activity;
   import android.os.Bundle;
   import android.view.View;
   import android.view.View.OnClickListener;
   import android.widget.Button;
   public class test extends Activity implements OnClickListener{
   Button btn;
   int count=0;
           public void onCreate(Bundle icicle)
           {
           super.onCreate(icicle);
           setContentView(R.layout.main);
           btn= (Button)findViewById(R.id.button1);
           btn.setOnClickListener(this);
           }
           public void onClick(View v) {
           // TODO Auto-generated method stub
           btn.setText(“Clicked “+ ++count + ” Times”);
           }
   }
Questions ?
My Android Blog:
1. http://www.boomtech.in
2. http://androidrox.wordpress.com

Contenu connexe

Tendances

Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming BasicsEueung Mulyana
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application FrameworkYong Heui Cho
 
Introduction to Android
Introduction to Android Introduction to Android
Introduction to Android Ranjith Kumar
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android StudioSuyash Srijan
 
android architecture
android architectureandroid architecture
android architectureAashita Gupta
 
Mobile application testing
Mobile application testingMobile application testing
Mobile application testingSoftheme
 
Android app development ppt
Android app development pptAndroid app development ppt
Android app development pptsaitej15
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studioParinita03
 
Synopsis on android application
Synopsis on android applicationSynopsis on android application
Synopsis on android applicationJawed akhtar
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting SequenceJayanta Ghoshal
 
Android summer training report
Android summer training reportAndroid summer training report
Android summer training reportShashendra Singh
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Androidma-polimi
 
Android Web app
Android Web app Android Web app
Android Web app Sumit Kumar
 

Tendances (20)

Introduction to android testing
Introduction to android testingIntroduction to android testing
Introduction to android testing
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming Basics
 
Android Platform Architecture
Android Platform ArchitectureAndroid Platform Architecture
Android Platform Architecture
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application Framework
 
Introduction to Android
Introduction to Android Introduction to Android
Introduction to Android
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android Studio
 
android architecture
android architectureandroid architecture
android architecture
 
Mobile application testing
Mobile application testingMobile application testing
Mobile application testing
 
Android app development ppt
Android app development pptAndroid app development ppt
Android app development ppt
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
 
Synopsis on android application
Synopsis on android applicationSynopsis on android application
Synopsis on android application
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
 
Android summer training report
Android summer training reportAndroid summer training report
Android summer training report
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
PPT on Android
PPT on AndroidPPT on Android
PPT on Android
 
Android Web app
Android Web app Android Web app
Android Web app
 

En vedette

Sensors in Android (old)
Sensors in Android (old)Sensors in Android (old)
Sensors in Android (old)Ahsanul Karim
 
Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesAhsanul Karim
 
Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedAhsanul Karim
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)Ahsanul Karim
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Ahsanul Karim
 
Android GPS Tutorial
Android GPS TutorialAndroid GPS Tutorial
Android GPS TutorialAhsanul Karim
 
Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Ahsanul Karim
 
Day 2 android internals a quick overview
Day 2 android internals a quick overviewDay 2 android internals a quick overview
Day 2 android internals a quick overviewAhsanul Karim
 
Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentAhsanul Karim
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsAhsanul Karim
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI WidgetsAhsanul Karim
 
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAndroid User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAhsanul Karim
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesAhsanul Karim
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Ahsanul Karim
 

En vedette (20)

Sensors in Android (old)
Sensors in Android (old)Sensors in Android (old)
Sensors in Android (old)
 
Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & Preferences
 
Client-Server
Client-ServerClient-Server
Client-Server
 
Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting Started
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
Android Services
Android ServicesAndroid Services
Android Services
 
List Views
List ViewsList Views
List Views
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3
 
Android GPS Tutorial
Android GPS TutorialAndroid GPS Tutorial
Android GPS Tutorial
 
Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)
 
Day 2 android internals a quick overview
Day 2 android internals a quick overviewDay 2 android internals a quick overview
Day 2 android internals a quick overview
 
Training android
Training androidTraining android
Training android
 
Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver Component
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
 
Android 1.8 sensor
Android 1.8 sensorAndroid 1.8 sensor
Android 1.8 sensor
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
 
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAndroid User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]
 

Similaire à Android fundamentals and tutorial for beginners

Android- Introduction for Beginners
Android- Introduction for BeginnersAndroid- Introduction for Beginners
Android- Introduction for BeginnersTripti Tiwari
 
Android architecture
Android architectureAndroid architecture
Android architectureDeepa Rahul
 
Android 1-intro n architecture
Android 1-intro n architectureAndroid 1-intro n architecture
Android 1-intro n architectureDilip Singh
 
Android Penetration Testing - Day 1
Android Penetration Testing - Day 1Android Penetration Testing - Day 1
Android Penetration Testing - Day 1Mohammed Adam
 
Presentation for Android OS
Presentation for Android OSPresentation for Android OS
Presentation for Android OSMukul Cool
 
Overview of Adroid Architecture.pptx
Overview of Adroid Architecture.pptxOverview of Adroid Architecture.pptx
Overview of Adroid Architecture.pptxdebasish duarah
 
Introduction to Android (before 2015)
Introduction to Android (before 2015)Introduction to Android (before 2015)
Introduction to Android (before 2015)Chien-Ming Chou
 
Introduction to android sessions new
Introduction to android   sessions newIntroduction to android   sessions new
Introduction to android sessions newJoe Jacob
 
01 what is android
01 what is android01 what is android
01 what is androidC.o. Nieto
 
Android OS and its Features
Android OS and its FeaturesAndroid OS and its Features
Android OS and its FeaturesHarshad Lokhande
 
Android Workshop Part 1
Android Workshop Part 1Android Workshop Part 1
Android Workshop Part 1NAILBITER
 
Introduction to android basics
Introduction to android basicsIntroduction to android basics
Introduction to android basicsHasam Panezai
 
Android Development Tutorial
Android Development TutorialAndroid Development Tutorial
Android Development TutorialGermán Bringas
 

Similaire à Android fundamentals and tutorial for beginners (20)

Android- Introduction for Beginners
Android- Introduction for BeginnersAndroid- Introduction for Beginners
Android- Introduction for Beginners
 
Android architecture
Android architectureAndroid architecture
Android architecture
 
Synapseindia android apps overview
Synapseindia android apps overviewSynapseindia android apps overview
Synapseindia android apps overview
 
Android 1-intro n architecture
Android 1-intro n architectureAndroid 1-intro n architecture
Android 1-intro n architecture
 
Android Penetration Testing - Day 1
Android Penetration Testing - Day 1Android Penetration Testing - Day 1
Android Penetration Testing - Day 1
 
Presentation for Android OS
Presentation for Android OSPresentation for Android OS
Presentation for Android OS
 
Android Technology
Android TechnologyAndroid Technology
Android Technology
 
Overview of Adroid Architecture.pptx
Overview of Adroid Architecture.pptxOverview of Adroid Architecture.pptx
Overview of Adroid Architecture.pptx
 
Introduction to Android (before 2015)
Introduction to Android (before 2015)Introduction to Android (before 2015)
Introduction to Android (before 2015)
 
Introduction to android sessions new
Introduction to android   sessions newIntroduction to android   sessions new
Introduction to android sessions new
 
My androidpresentation
My androidpresentationMy androidpresentation
My androidpresentation
 
01 what is android
01 what is android01 what is android
01 what is android
 
Android OS and its Features
Android OS and its FeaturesAndroid OS and its Features
Android OS and its Features
 
Android Workshop Part 1
Android Workshop Part 1Android Workshop Part 1
Android Workshop Part 1
 
Introduction to android basics
Introduction to android basicsIntroduction to android basics
Introduction to android basics
 
Hello androidforyarlmeetup
Hello androidforyarlmeetupHello androidforyarlmeetup
Hello androidforyarlmeetup
 
Android OS
Android OSAndroid OS
Android OS
 
Android Anatomy
Android  AnatomyAndroid  Anatomy
Android Anatomy
 
Android primer
Android primerAndroid primer
Android primer
 
Android Development Tutorial
Android Development TutorialAndroid Development Tutorial
Android Development Tutorial
 

Dernier

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Dernier (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Android fundamentals and tutorial for beginners

  • 1.
  • 2. Android Basics - Bhaumik Shukla Android Application Developer @ STEALTH FLASH
  • 3. Introduction to Android • Android is a software stack for mobile devices that includes an operating system, middleware and key applications. • The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
  • 4. Introduction to Android • Android is an open-source platform developed under the Open Handset Alliance to enable faster development of mobile applications and provision of services to the user. • Google is the leading company to develop and promote Android, however there are other companies as well who are involved in the development of Android. Some of these include T-Mobile, HTC, Qualcomm and others.
  • 5. Features • Application framework enabling reuse and replacement of components • Dalvik virtual machine optimized for mobile devices • Integrated browser based on the open source WebKit engine • Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional) • SQLite for structured data storage • Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF) • GSM Telephony (hardware dependent) • Bluetooth, EDGE, 3G, and WiFi (hardware dependent) • Camera, GPS, compass, and accelerometer (hardware dependent) • Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE
  • 6. Tools • Emulator – Android applications may be run on a real device or on the Android Emulator, which ships with the Android SDK. • ADB (Android Debug Bridge) – The ADB utility lets you connect to the phone itself and issue rudimentary shell commands, such as copying files to and from the device.
  • 8. Applications • Android will ship with a set of core applications including an email client, SMS program, calendar, maps, browser, contacts, and others. All applications are written using the Java programming language.
  • 9. Application Framework • A rich and extensible set of Views that can be used to build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser • Content Providers that enable applications to access data from other applications (such as Contacts), or to share their own data • A Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files • A Notification Manager that enables all applications to display custom alerts in the status bar • An Activity Manager that manages the lifecycle of applications and provides a common navigation backstack
  • 10. Libraries • System C library - a BSD-derived implementation of the standard C system library (libc), tuned for embedded Linux-based devices • Media Libraries - based on PacketVideo's OpenCORE; the libraries support playback and recording of many popular audio and video formats, as well as static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG • Surface Manager - manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applications • LibWebCore - a modern web browser engine which powers both the Android browser and an embeddable web view • SGL - the underlying 2D graphics engine • 3D libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries use either hardware 3D acceleration (where available) or the included, highly optimized 3D software rasterizer • FreeType - bitmap and vector font rendering • SQLite - a powerful and lightweight relational database engine available to all applications
  • 11. Android Runtime • Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language. • Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included "dx" tool. • The Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management.
  • 12. Linux Kernel • Android relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. The kernel also acts as an abstraction layer between the hardware and the rest of the software stack.
  • 13. Application Fundamentals • Apps are written in Java • Bundled by Android Asset Packaging Tool • Every App runs its own Linux process • Each process has it’s own Java Virtual Machine • Each App is assigned a unique Linux user ID • Apps can share the same user ID to see each other’s files
  • 14. Application Fundamentals • Android applications are written in the Java programming language. The Android SDK tools compile the code—along with any data and resource files—into an Android package, an archive file with an .apk suffix. All the code in a single .apk file is considered to be one application and is the file that Android-powered devices use to install the application.
  • 15. Application Components • Application components are the essential building blocks of an Android application. Each component is a different point through which the system can enter your application. Not all components are actual entry points for the user and some depend on each other, but each one exists as its own entity and plays a specific role—each one is a unique building block that helps define your application's overall behavior.
  • 16. Application Components • Activities – An activity represents a single screen with a user interface. – Present a visual user interface for one focused endeavor the user can undertake – Example: a list of menu items users can choose from, or anything.
  • 17. Application Components • Services – A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. – A service does not provide a user interface. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it.
  • 18. Application Components • Content providers – A content provider manages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Through the content provider, other applications can query or even modify the data (if the content provider allows it). For example, the Android system provides a content provider that manages the user's contact information. As such, any application with the proper permissions can query part of the content provider (such as ContactsContract.Data) to read and write information about a particular person.
  • 19. Application Components • Broadcast receivers – A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. – Receive and react to broadcast announcements – Example: announcements that the time zone has changed
  • 20. Application Components • Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an intent. • Intents bind individual components to each other at runtime (you can think of them as the messengers that request an action from other components), whether the component belongs to your application or another. • An intent is created with an Intent object, which defines a message to activate either a specific component or a specific type of component—an intent can be either explicit or implicit, respectively.
  • 21. Application Components • There are separate methods for activiting each type of component: • You can start an activity (or give it something new to do) by passing an Intent to startActivity() or startActivityForResult() (when you want the activity to return a result). • You can start a service (or give new instructions to an ongoing service) by passing an Intent to startService(). Or you can bind to the service by passing an Intent to bindService(). • You can initiate a broadcast by passing an Intent to methods like sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast(). • You can perform a query to a content provider by calling query() on a ContentResolver.
  • 22. The Manifest File • Before the Android system can start an application component, the system must know that the component exists by reading the application's AndroidManifest.xml file (the "manifest" file). Your application must declare all its components in this file, which must be at the root of the application project directory. • The manifest does a number of things in addition to declaring the application's components, such as: • Identify any user permissions the application requires, such as Internet access or read-access to the user's contacts. • Declare the minimum API Level required by the application, based on which APIs the application uses. • Declare hardware and software features used or required by the application, such as a camera, bluetooth services, or a multitouch screen. • API libraries the application needs to be linked against (other than the Android framework APIs), such as the Google Maps library. • And more
  • 23. The Manifest File The primary task of the manifest is to inform the system about the application's components. For example, a manifest file can declare an activity as follows: ----------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?> <manifest ... > <application android:icon="@drawable/app_icon.png" ... > <activity android:name=".ExampleActivity" android:label="@string/example_label" ... > </activity> ... </application> </manifest>
  • 24. Application Resources • An Android application is composed of more than just code—it requires resources that are separate from the source code, such as images, audio files, and anything relating to the visual presentation of the application. • For example, you should define animations, menus, styles, colors, and the layout of activity user interfaces with XML files. Using application resources makes it easy to update various characteristics of your application without modifying code and—by providing sets of alternative resources—enables you to optimize your application for a variety of device configurations (such as different languages and screen sizes).
  • 26. Activity callbacks • onCreate() Called when the activity is first created. This is where you should do all of your normal static set up — create views, bind data to lists, and so on. This method is passed a Bundle object containing the activity's previous state, if that state was captured (see Saving Activity State, later). Always followed by onStart(). • onRestart() Called after the activity has been stopped, just prior to it being started again. Always followed by onStart() • onStart() Called just before the activity becomes visible to the user. Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden. • onResume() Called just before the activity starts interacting with the user. At this point the activity is at the top of the activity stack, with user input going to it. Always followed by onPause().
  • 27. Activity callbacks • onPause() Called when the system is about to start resuming another activity. This method is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, and so on. It should do whatever it does very quickly, because the next activity will not be resumed until it returns. Followed either by onResume() if the activity returns back to the front, or by onStop() if it becomes invisible to the user. • onStop() Called when the activity is no longer visible to the user. This may happen because it is being destroyed, or because another activity (either an existing one or a new one) has been resumed and is covering it. Followed either by onRestart() if the activity is coming back to interact with the user, or by onDestroy() if this activity is going away.
  • 28. Activity callbacks • onDestroy() Called before the activity is destroyed. This is the final call that the activity will receive. It could be called either because the activity is finishing (someone called finish() on it), or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.
  • 29. Declaring Activity • Declaring the activity in the manifest • You must declare your activity in the manifest file in order for it to be accessible to the system. To declare your activity, open your manifest file and add an <activity> element as a child of the <application> element. For example: <manifest ... > <application ... > <activity android:name=".ExampleActivity" /> ... </application ... > ... </manifest >
  • 30. View Groups • FrameLayout Layout that acts as a view frame to display a single object. • Gallery A horizontal scrolling display of images, from a bound list. • GridView Displays a scrolling grid of m columns and n rows. • LinearLayout A layout that organizes its children into a single horizontal or vertical row. It creates a scrollbar if the length of the window exceeds the length of the screen. • ListView Displays a scrolling single column list. • RelativeLayout Enables you to specify the location of child objects relative to each other (child A to the left of child B) or to the parent (aligned to the top of the parent). • ScrollView A vertically scrolling column of elements. • etc..
  • 32. Write XML for UI design • Using Android's XML vocabulary, you can quickly design UI layouts and the screen elements they contain, in the same way you create web pages in HTML — with a series of nested elements. sample main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, I am a TextView" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, I am a Button" /> </LinearLayout>
  • 33. Installation • How to install & configure Android SDK and Eclipse http://developer.android.com/sdk/installing.html
  • 34. Configure AVD http://developer.android.com/guide/developing/devices/managing-avds.html • Creating an AVD • You can create as many AVDs as you would like to test on. It is recommended that you test your applications on all API levels higher than the target API level for your application. • To create an AVD: • Start the AVD Manager: – In Eclipse: select Window > Android SDK and AVD Manager, or click the Android SDK and AVD Manager icon in the Eclipse toolbar. – In other IDEs: Navigate to your SDK's tools/ directory and execute the android tool with no arguments. • In the Virtual Devices panel, you'll see a list of existing AVDs. Click New to create a new AVD. The Create New AVD dialog appears.
  • 37. First Android Project • Select File > New > Project. • Select Android > Android Project, and click Next. • Select the contents for the project: – Enter a Project Name. – Under Target, select an Android target to be used as the project's Build Target – Under Properties, fill in all necessary fields. • Enter an Application name. • Enter a Package name. • Select Create Activity (optional, of course, but common) and enter a name for your main Activity class. • Enter a Min SDK Version • Click Finish.
  • 38. Your Android project is now ready. It should be visible in the Package Explorer on the left. Open the HelloAndroid.java file, located inside HelloAndroid > src > com.example.helloandroid). It should look like this: • package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
  • 39. res/layout/main.xml <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/textview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/hello"/> res/layout/strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello, Android! I am a string resource!</string> <string name="app_name">Hello, Android</string> </resources>
  • 40. Handling UI Events • On Android, there's more than one way to intercept the events from a user's interaction with your application. When considering events within your user interface, the approach is to capture the events from the specific View object that the user interacts with. The View class provides the means to do so. • Event Listeners An event listener is an interface in the View class that contains a single callback method. These methods will be called by the Android framework when the View to which the listener has been registered is triggered by user interaction with the item in the UI.
  • 41. Handling UI Events • onClick() From View.OnClickListener. • onLongClick() From View.OnLongClickListener. • onFocusChange() From View.OnFocusChangeListener. • onKey() From View.OnKeyListener. • onTouch() From View.OnTouchListener. • onCreateContextMenu() From View.OnCreateContextMenuListener.
  • 42. How to write Click event • The example below shows how to register an on-click listener for a Button. // Create an anonymous implementation of OnClickListener private OnClickListener mCorkyListener = new OnClickListener() { public void onClick(View v) { // do something when the button is clicked } }; protected void onCreate(Bundle savedValues) { ... // Capture our button from layout Button button = (Button)findViewById(R.id.btn); // Register the onClick listener with the implementation above button.setOnClickListener(mCorkyListener); ... }
  • 43. How to write Click event • You may also find it more convenient to implement OnClickListener as a part of your Activity. This will avoid the extra class load and object allocation. For example: public class ExampleActivity extends Activity implements OnClickListener { protected void onCreate(Bundle savedValues) { ... Button button = (Button)findViewById(R.id.btn); button.setOnClickListener(this); } // Implement the OnClickListener callback public void onClick(View v) { // do something when the button is clicked } ... }
  • 44. Example Button Click example counts the clicks. • We need a to declare activity in AndroidManifest.xml file <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test" android:versionCode="1" android:versionName="1.0“> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".test" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
  • 45. Example Button Click example counts the clicks. • We need a button in main.xml <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout android:id=”@+id/linear1″ android:layout_width=”fill_parent” android:layout_height=”fill_parent” xmlns:android=”http://schemas.android.com/apk/res/android”> <Button android:text=”ClickMe” android:id=”@+id/button1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”></Button> </LinearLayout>
  • 46. Example Button Click example counts the clicks. Activity.Java package com.example.test; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class test extends Activity implements OnClickListener{ Button btn; int count=0; public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); btn= (Button)findViewById(R.id.button1); btn.setOnClickListener(this); } public void onClick(View v) { // TODO Auto-generated method stub btn.setText(“Clicked “+ ++count + ” Times”); } }
  • 48. My Android Blog: 1. http://www.boomtech.in 2. http://androidrox.wordpress.com