• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Android Tutorial
 

Android Tutorial

on

  • 2,916 views

Android Tutorial by Mr. Manjeet Singh, Module Lead, Spice Labs. He is presenting at Verious presents OpenClass - Android Developers Day.

Android Tutorial by Mr. Manjeet Singh, Module Lead, Spice Labs. He is presenting at Verious presents OpenClass - Android Developers Day.

Statistics

Views

Total Views
2,916
Views on SlideShare
2,915
Embed Views
1

Actions

Likes
5
Downloads
0
Comments
1

1 Embed 1

http://www.verious.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Thanks for the nice tutorials.. Even this http://www.compiletimeerror.com/2013/07/android-tutorials.html might help... Have a look..
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Android Tutorial Android Tutorial Presentation Transcript

    • Verious Presents OpenClass – Android Developers Day www.openclass.in Event Organized on September 24, 2011
    • Agenda
      • Android System Architecture
      • GUI Design
      • Services and Broadcast Receivers
      Android
    • Android System Architecture
    • 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.
      • New Android specific components have been added
      • Alarm, Android Shared Memory
      • Kernel Memory Killer, Kernel Debugger, Loger
    • Libraries Android Libraries implementation Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework.
    • Core Libraries
      • System C library - a BSD-derived implementation of the standard C system library (libc), tuned for embedded Linux-based devices
      • Surface Manager - Provides a system-wide surface “composer” to render all the surfaces in a frame buffer
        • Can combined 2D and 3D surfaces
        • Can use OpenGL ES and 2D hardware accelerator for its compositions
      • Storage (SQLite) – a powerful and lightweight relational database engine available to all applications
      • WebKit – an Application framework that provides foundation for building a web browser.
    • Core Libraries (Cont..)
      • 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
    • 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 Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management.
    • Application Framework
      • Android offers developers the ability to build extremely rich and innovative applications. Developers are free to take advantage of the device hardware, access location information, run background services, set alarms, add notifications to the status bar, and much, much more.
      • Application Framework Layer
      • Activity Manager handles application lifecycle
      • Package Manager holds information about applications loaded in the system
      • Windows Manager handles all the application related windows
      • View system provides 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
    • Application Framework (Cont..)
      • Resource Manager , providing access to non-code resources such as localized strings, graphics, and layout files
      • Content Providers that enable applications to access data from other applications (such as Contacts), or to share their own data
      • Notification Manager that enables all applications to display custom alerts in the status bar
      • Location Manager that provides location information.
      • Telephony Manager that provides telephone related events such as incoming/outgoing call
    • Application
      • Android provides 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.
      • GUI (Layout) Design
    • Android UI
      • In an Android application, the user interface is built using View and ViewGroup objects. There are many types of views and view groups, each of which is a descendant of the View class.
      • View objects are the basic units of user interface expression on the Android platform. The View class serves as the base for subclasses called "widgets," which offer fully implemented UI objects, like text fields and buttons. The ViewGroup class serves as the base for subclasses called "layouts," which offer different kinds of layout architecture, like linear, tabular and relative.
    • View Hierarchy Layouts (Linear/Relative) It can be TextView, Button or any other Widget
    • Creating a UI
      • Android provides us Facility of creating UI in two ways:
      • 1. Creating XML under Layout directory
      • 2. Create widgets with in Java application
    • Creating XML under Layout directory
      • <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
      • <LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      • android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot;
      • android:orientation=&quot;vertical&quot; >
      • <TextView android:id=&quot;@+id/text&quot;
      • android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;
      • android:text=&quot;Hello, I am a TextView&quot; />
      • <Button android:id=&quot;@+id/button&quot;
      • android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;
      • android:text=&quot;Hello, I am a Button&quot; />
      • </LinearLayout>
    • Create widgets with Java application
      • TextView valueTV = new TextView(this);
      • valueTV.setText(&quot;hallo hallo&quot;);
      • valueTV.setId(5);
      • valueTV.setLayoutParams(new LayoutParams(
      • LayoutParams.FILL_PARENT,
      • LayoutParams.WRAP_CONTENT));
    • Difference XML Based UI UI created within Application 1. It is easy to create as one can create UI using design tool. No development skill required for this. 2. This helps developer to create consistant UI. If property of any component is modified in XML then same changes will be reflected everywhere, where component is used. 1. This require testing every time user add any component if developer makes any changes. 2. Developer need to dig into the code and need to find all usage and replace and test every case as he/she may forget to keep update to same properties everywhere. So its time consming process for developers.
    • Layout resources in Android
      • One thing that often confuses developers new to the Android platform is the handling of layout resources. The xml files describing the layouts are magically transfered into a more efficient binary format behind the scenes and hidden away - leaving the developer with a static reference to the resources via the R.java file.
      • By using the setContentView(int layoutResId) method of the Activity class your layout will be displayed on the screen. Behind the scenes the Android platform is creating all the view objects contained in your layout xml file provided to the setContentView(int layoutResId) method. This process of creating view objects out of layout resources is referred to as layout inflation.
    • LayoutInflater
      • To avoid these errors it's a good habit to place the setContentView(int layoutResId) method call at the very top of the onCreate() method.
      • In some cases you will have to do the layout inflation by yourself, i.e. when you want to set a custom view to a Dialog or a Toast. To inflate a view you use the LayoutInflater class. There's a number of different ways to get a handle to a LayoutInflater:
      • LayoutInflater inflater = (LayoutInflater)context.getSystemService(
      • Context.LAYOUT_INFLATER_SERVICE); OR
      • LayoutInflater inflater = LayoutInflater.from(context);
      • View view = linflater.inflate(R.layout.inflate_xml, null);
      • TextView tv = (TextView) view.findViewById(R.id.textview_xml);
      • mainLayout.addView(view);
    • Android Services and Broadcast Receiver
    • Services
      • A service is a component which runs in the background, without interacting with the user.
      • The Android platform provides a lot of pre-defined services, usually exposed via a Manager class. In your activity you access services via the method getSystemService().
      • Own Services must be declared via the &quot;AndroidManifest.xml&quot;. They run the main thread of their hosting process. Therefore you should run performance intensive tasks in the background .
    • Own Services
      • You can declare your own service to perform long running operations without user interaction or to supply functionality to other applications. A activity can start a service via the startService() method and stop the service via the stopService() method. If the activity want to interact with the service it can use the bindService() method of the service. This requires an &quot;ServiceConnection&quot; object which allows to connect to the service and which return a IBinder object. This IBinder object can be used by the activity to communicate with the service.
      • Once a service is started its onCreate() method is called. Afterwards the onStartCommand() is called with the Intent data provided by the activity. startService also allows to provide a flag with determines the lifecycle behavior of the services
      • A Services needs to be declared in the &quot;AndroidManifest.xml&quot; via a <service android:name=&quot;yourclasss&quot;> </service> and the implementing class must extend the class &quot;Service&quot; or one of its subclasses.
    • Broadcast Receiver A broadcast receiver is a class which extends &quot;BroadcastReceiver&quot; and which is registered as a receiver in an Android Application via the AndroidManifest.xml (or via code). This class will be able to receive intents via the sendBroadcast() method. &quot;BroadCastReceiver&quot; defines the method &quot;onReceive()&quot;. Only during this method your broadcast receiver object will be valid, afterwards the Android system will consider your object as no longer active. Therefore you cannot perform any asynchronous operation. AndroidManifest.XML <receiver android:name=&quot;MyPhoneReceiver&quot;> <intent-filter> <action android:name=&quot;android.intent.action.PHONE_STATE&quot;> </action> </intent-filter> </receiver>
    • Broadcast Receiver Example
      • public class MyPhoneReceiver extends BroadcastReceiver {
      • @Override
      • public void onReceive(Context context, Intent intent) {
      • Bundle extras = intent.getExtras();
      • if (extras != null) {
      • String state = extras.getString(TelephonyManager.EXTRA_STATE);
      • if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
      • String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER;
      • Log.w(&quot;DEBUG&quot;, phoneNumber);
      • } } } }