78_a industrial trainning report for cs.doc

Upload: manu

Post on 02-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    1/34

    AN INDUSTRIAL TRAINNING REPORTON

    Basic Android

    Submitted in Partial Fulfillment for the award of Bachelor of Engineering in o!"#$er Science % Engineering &'()*+'(),-

    Submitted toRA.I/ GAND0I PROUD1OGI2I /IS03A/ID1ALA1AB0OPAL &45P5-

    Submitted By:Na!e A6an6sha "ande7

    &(8('cs)))()(-

    Approved By Under the Guidance of

    4r5B5P5Singh 4r599999999999 (Head of the Department (!S Dept" !omputer Science

    DEPART4ENT O: O4PUTER S IEN E % ENGINEERING/IND01A INSTITUTE O: TE 0NOLOG1 AND S IEN E

    SATNA &45P5-

    #

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    2/34

    Ra;i< Gandhi Pro#d7ogi6i /ish=a

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    3/34

    05O5D G#ided B74r5B5P5Singh 4r599999999999

    (Head of the Department (!S Dept" !omputer Science

    Princi"al

    4r5R5 5Shri

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    4/34

    Computer cience & Engineering for the

    session !"#$%!"# )

    &E?$ernal E?a!iner- &In$ernal E?a!iner-

    A 2NO3LEDGE4ENT

    A pro-ect li.e thi+ one involve+ many people and would be in completewithout the mention of all tho+e people who+e /uidance and encoura/ementhelped in the +ucce++ful completion of thi+ pro-ect

    0ur heartily than's to all faculty member of *epartment of

    computerscience

    +IT atna for their e,ort toward our pro-ect)

    1

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    5/34

    DE LARATION

    2e here by declare that the wor. which i+ bein/ completed in the 'ndu+trial&rainin/ Basic Android 'n partial fulfillment of the re3uirement of the

    de/ree of Bachelor of Engineering in o!"#$er Science %

    Engineering branch i+ an authentic record of our wor. carried out under

    4

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    6/34

    the able /uidance of Tar#n @a!@a5 &he wor. ha+ been carried out at

    RISP Bho"al5

    Training Associa$e

    Na!e &(8('cs)))()(-

    !05&$5:6'ntroduction

    ):6Feature+

    ,:6Application

    1:6ver+ion+

    4:6Dia/ram+

    7:6Activity

    8:69i+tener method+

    7

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    7/34

    :6pha+e+

    ;:6!onclu+ion

    #

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    8/34

    '5&%0DU!&'05

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    9/34

    2hat i+ Android>

    Android i+ an open +ource and 9inu?6ba+ed O"era$ing S7s$e! for mobiledevice+ +uch a+ +martphone+ and tablet computer+" Android wa+ developed

    by the Open Handset Alliance @ led by Goo/le@ and other companie+"

    Android offer+ a unified approach to application development for mobiledevice+ which mean+ developer+ need only develop for Android@ and theirapplication+ +hould be able to run on different device+ powered by Android"

    &he fir+t beta ver+ion of the Android (SD wa+ relea+ed by Goo/le in )

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    10/34

    FEATURES

    #

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    11/34

    Features o f Android

    Android is a powerful operating system competing with Apple 4GS and supportsgreat features. Few of them are listed below:

    Feature

    Beautiful UI

    Connectivity

    Storage

    Mediasupport

    Messaging

    ##

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    12/34

    Webbrowser

    Multi-touch

    Multi-tasking

    Resizablewidgets

    Multi-Language

    GCM

    Wi-Fi Direct

    AndroidBeam

    Android Applications

    Android applications are usually developed in the Java languageusing the Android Software Development Kit.

    Once developed, Android applications can be packaged easily andsold out either through a store such as Google P lay or the Amazon

    Appstore .

    Android powers hundreds of millions of mobile devices in more than190 countries around the world. It's the largest installed base of anymobile platform and growing fast. Every d ay more than 1 million new

    #)

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    13/34

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    14/34

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    15/34

    data, libraries to play and record audio and video, S SL librariesresponsible for Internet security etc.

    Android Runtime

    This is the third section of the architecture and available on thesecond layer from the bottom. This se ction provides a key c omponentcalled Dalvik Virtual Machine which is a kind of Java VirtualMachine specially d esigned and optimized for Android.

    The Dalvik VM makes use of Linux core features like memorymanagement an d multi-threading, which is intrinsic in the Javalanguage. The Dalvik VM enables e very Android application to run inits own process, with its own instance of the Dalvik virtual machine.

    The Android runtime also provides a set of core libraries w hich enableAndroid application developers to write Android applications usingstandard Java programming language.

    Application Framework

    The Application Framework layer provides m any h igher-level servicesto applications i n the form of Java classes. Application developers a reallowed to make use of these services i n their applications.

    Applicationsthat can be used within an You will nd all the Android application atthe top layer. You will write your a pplication to be installed on thislayer only. Examples of su ch applications are Contacts Books,Browser, Games et c.

    #4

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    16/34

    VERSIONS

    #7

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    17/34

    #8

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    18/34

    Manly e ight versions ar e u sed in android:

    @Cupcake 1.5

    @Donut 1.6

    @Eclairs 2 .0-2.1

    @Froyo 2.2

    @Honey comb 3.0-3.2

    @Ice-cream sandwich 4.0+

    @Jelly bean 4 .1-1

    @Kitket 4.4

    #

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    19/34

    #;

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    20/34

    ComponentsApplication components are the essential building blocks of anAndroid application. These components are loosely coupled by theapplication manifest le AndroidManifest.xml that describes eachcomponent of the application and how they interact.

    There a re following four main c omponents Android a pplication:

    Components Description

    Activities They d ictate the UI and handle the user interactionto the sm artphone sc reen

    Services They handle background processing associatedwith an application.

    BroadcastReceivers

    They ha ndle com munication between Android OSand applications.

    ContentProviders

    They hand le da ta an d database m anagementissues.

    Activities

    An activity represents a single screen with a user interface. F orexample, an email application might have one activity that shows alist of new emails, another activity to compose an email, and another

    )

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    21/34

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    22/34

    The R File

    The gen/com.example.helloworld/R.java le is the glue betweenthe activity Java les like MainActivity.java and the resources likestrings.xml . It is an automatically generated le and you should not

    modify the content of the R.java le. Following is a sample of R.javale:

    The Layout File

    The activity_main.xml is a layout le available in res/layout directory,that is r eferenced by y our application when building its i nterface. Youwill modify t his le very f requently t o change the layout of yourapplication. For your "Hello World!" application, this le will havefollowing content related to default layout

    The Activity class denes the following callbacks i.e. eve nts. Y ou

    ))

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    23/34

    don't ne ed to implement al l the callbacks methods. H owever, it'simportant that you understand each one and implement those thatensure your app behaves t he way u sers exp ect.

    Callback Description

    onCreate()

    This i s t he rst callback a nd called when the activity i srst created.

    OnStart() This ca llback is ca lled when the activity becomesvisible to the user.

    OnResume()

    This i s c alled when the user starts i nteracting with theapplication.

    OnPause()The paused activity does n ot receive u ser input andcannot execute any co de and called when the currentactivity is being paused and the previous activity isbeing resumed.

    OnStop() This ca llback i s ca lled when the activity is n o longervisible.

    OnDestroy()

    This c allback i s c alled before the activity i s d estroyedby the system.

    OnRestart()

    This callback is called when the activity restarts afterstopping it.

    Example

    This example will take you through simple steps to show Androidapplication activity life cycle. Follow the following steps to modify theAndroid application we created in Hello World Example ch apter:

    st Description

    ),

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    24/34

    1 You will use Eclipse IDE to create an Android application andname it as HelloWorld under a p ackagecom.example.helloworld a s e xplained in the Hello WorldExample ch apter.

    2 Modify main a ctivity le MainActivity.java as e xplained below.Keep rest of the les u nchanged.

    3 Run the application to launch Android emulator and verify theresult of the changes d one in the aplication.

    Following is the content of the modied main activityle src/com.example.helloworld/MainActivity.java . This le includeseach of the fundamental lifecycle methods. The Log.d() method hasbeen used to generate log messages:

    package com. example . helloworld ;import android . os . Bundle ; import android . app . Activity ; import android . util . Log ;

    publicclass MainActivity extends Activity {String msg !Android #! ;

    A service is a component that runs in the background to performlong-running operations without needing to interact with the user. Forexample, a service might play music in the background while the useris in a different application, or i t might fetch data over t he networkwithout b locking user interaction with an activity. A service can

    essentially take two states:

    A service has lifecycle callback methods that you can implement tomonitor changes in the service's st ate and you can perform work a tthe appropriate stage. The following diagram on the left shows thelifecycle when the service is created with startService() a nd the

    )1

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    25/34

    diagram on the right shows the lifecycle when the service is createdwith bindService(): (image courtesy : android.com )

    To create an service,you create a Java class t hat extends t he Service base class o r one ofits existing subclasses. T he Service base class denes variouscallback m ethods a nd the most important are given below. You don'tneed to implement all the callbacks methods. However, it's importantthat you understand each one and implement those that ensure yourapp behaves t he way use rs expe ct.

    all@ac6 Descri"$ion

    onStart!om &he +y+tem call+ thi+ method when another component@

    )4

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    26/34

    mand( +uch a+ an activity@ re3ue+t+ that the +ervice be +tarted@ bycallin/ startService() " 'f you implement thi+ method@ it i+your re+pon+ibility to +top the +ervice when it+ wor. i+done@ by callin/ stopSelf() or stopService() method+"

    onBind( &he +y+tem call+ thi+ method when another componentwant+ to bind with the +ervice by callin/ bindService() " 'fyou implement thi+ method@ you mu+t provide an interfacethat client+ u+e to communicate with the +ervice@ byreturnin/ an IBinder ob-ect" =ou mu+t alway+ implementthi+ method@ but if you don t want to allow bindin/@ then

    you +hould return null "onUnbind( &he +y+tem call+ thi+ method when all client+ have

    di+connected from a particular interface publi+hed by the+ervice"

    on%ebind( &he +y+tem call+ thi+ method when new client+ haveconnected to the +ervice@ after it had previou+ly beennotified that all had di+connected in it+ onUnbind(Intent) "

    on!reate( &he +y+tem call+ thi+ method when the +ervice i+ fir+t

    created u+in/ onStartCommand() or onBind() " &hi+ call i+re3uired to perform one6time +etup"

    onDe+troy( &he +y+tem call+ thi+ method when the +ervice i+ no lon/eru+ed and i+ bein/ de+troyed" =our +ervice +houldimplement thi+ to clean up any re+ource+ +uch a+ thread+@re/i+tered li+tener+@ receiver+@ etc"

    Create Content Provider

    )7

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    27/34

    This involves number of simple steps to create your ow n contentprovider.

    First of all you need to create a Content Provider class that extendsthe ContentProviderbase class.

    Second, you need to dene your content provider URI address whichwill be used to access the content.

    Next you will need to create your own database to keep the content.Usually, Android uses SQLite database and framework needs tooverride onCreate() method which will use SQLite Open Helper

    method to create or open the provider's database. When yourapplication is launched,the onCreate() handler of each of its ContentProviders i s c alled on the main application thread.

    Next you will have to implement Content Provider queries t o performdifferent database specic operations.

    Finally register your C ontent P rovider in your acitivity le using tag.

    Here is the list of methods which you need to override in ContentProvider class t o have your Content Provider working:

    onCreate()

    This m ethod is c alled when the provider is s tarted.

    )8

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    28/34

    query()

    This method receives a request from a client. The result is returnedas a Cursor object.

    insert()This m ethod inserts a new record into the content provider.

    delete()

    This m ethod deletes a n existing record from the content provider.

    update()

    This m ethod updates a n existing record from the content provider.getType() This m ethod returns t he MIME type of the data at the givenURI.

    )

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    29/34

    );

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    30/34

    The application can embed two fragments in Activity A, when runningon a tablet-sized device. However, on a handset-sized screen, there'snot enough room for both fragments, so Activity A includes only thefragment for the list of articles, and when the user selects a n article, itstarts Activity B, which includes the second fragment to read thearticle.

    Fragment Life Cycle

    Android fragments have their own life cycle very s imilar to an androidactivity. This section briefs different stages of its life cycle.

    ,

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    31/34

    Phase I: When a fragment getscreated, it goes through thefollowing states:

    onAttach()

    onCreate()

    onCreateView()

    onActivityCreated()

    Phase II: When the fragment

    becomes visible, it goes throughthese states:

    onStart()

    onResume()

    Phase III: When the fragmentgoes into the background mode,

    it goes t hrough these states:

    onPaused()

    onStop()

    Phase IV: When the fragment isdestroyed, it goes through thefollowing states:

    onPaused()

    onStop()

    onDestroyView()

    ,#

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    32/34

    onDestroy()

    onDetach()

    How to use F ragments?

    This i nvolves n umber of simple steps t o create Fragments.

    First of all decide how many fragments yo u want to use in an activity.Fors e xample let's w e want to use two fragments t o handle landscapeand portrait modes o f the device.

    Next based on number of fragments, create classes w hich will extendthe Fragment class. The Fragment class has above mentionedcallback functions. You can override any of the functions based onyour requirements.

    Corresponding to each fragment, you will need to create layout les i nXML le. These les w ill have layout for the dened fragments.

    Finally modify activity le to dene the actual logic of replacingfragments b ased on your requirement.

    Here is t he list of important methods w hich you can to override in yourfragment class:

    onCreate() The system calls this when creating the fragment. Youshould initialize essential components of the fragment that you wantto retain when the fragment is p aused or stopped, then resumed.

    onCreateView() The system calls this callback when it's time for thefragment to draw its user interface for the rst time. To draw a UI foryour fragment, you must return a View com ponent from this m ethod

    ,)

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    33/34

    that is the root of your fragment's layout. You can return null if thefragment does n ot provide a UI.

    onPause() The system calls this method as the rst indication thatthe user is leaving the fragment. This is usually where you shouldcommit any changes t hat should be persisted beyond the current user

    session.

    ,,

  • 8/10/2019 78_A INDUSTRIAL TRAINNING REPORT FOR CS.doc

    34/34