You are on page 1of 43
VALIA COLLEGE OF ARTS, COMMERCE & SCIENCE PRESENTS, Advanced Mobile Programming Practical T.Y.B.Se.I.T- SEM VI Copyright © PROF, GUFRAN QURESHI 9029120671 / 7021047199 rae nau nt ect stn Sone Jppnen nema: ey =p oN vs Ses Foner ore oe es s,s py ede Ae Oren Spe HM | renga ater, Segre Gretna) 2 | repammng ees rogue Co Abra RDO UE ECON MCE TE (| repanmeg ees rane: an Le, abe, ea ane Lo, 5 | Peanneg ul wanens Fra Jomo | Pegamng nea ag arog 1 [ean ements Eres tees aes: hea rt ng estes 1 | repo Feist nant ce [ona Progaming 20.8 [anne ens nts sapere ognns | repens anagem | rang Seat pers | anne te Communion 4 Ses 00) Introduction to Android: etna: Ani ian open sours an Linztased opting system for mail device ich ‘smanhones an bet comput And was developed by the Open Hands Alans el ty Gog, an ote compen. Ando offers sued aproich o application development fr mail devices which means devetopes need only develop fc Ano, and tt splctions shold be tle ran oa Gite deve powered y Ami «€ ‘The fist beta version of he Ani Software Developnet Kit (SDK) ws tkeased by Got in 2107 whet asthe fist commer eso, Android 1.0, lessed in epee 2008 {mde 27.2012, the Google LO conferees, Google enone the next Anis vein 441 Jelly Bean, ly Beans a incremental ype, with ce primary aim of inroving the wer inert, ohn ens of tonya peor, “he soc coe fe Ad ie ase wr fad open totes sofware Useees, Google publi mst ofthe onde over the Apache Less yen 20 aa ter Lins eae ‘Shans, oder the GNU General Publi License veson 2 Why Androtd ? Software Required core nc emcon 1. Android Studios hps:/developer android com studio 2. SDK-dk-But3H: hips: 5 7 1 1. Android Studio: Andtoid Studio is the offical intograted development environment for Google's Android operating system, built on JetBrains Intell IDEA software and designed specifically for Andtoid development. It provides & Unified environment where you can build pps for Android phones, tablets, Andoid Wear, Andtoid: TY, and Android Auto, Structured code modules allow you to divide your project into units of functionality that you can ‘ndopendonly build, test, and debug. 2. SDK: A software development it (SDK) isa colleton of software development fools in one installable package. They facilitate the ereation of applications by having compiler, debugger and perhaps a software framework. They a normally spoific toa hardware platform and operating system combination, Practical 1: Introduction to Android Studio IDE, ree» sx» Application Fundamentals Theory: Anda Studi is the oficial inegited development environment IDE) fr Google's Android opting Syston, bil on JeBrsin Intell IDEA software and designed specially fr Android development iisavalale or dovnload on Windows, macOS and Linux based operating systems The vorson usd in th following practical is Teeogies « mininum of 3G RAM and wed IDK application fdamentals. And aps canbe writen sng Kodi, fave and Clog, Features: “The following features are provided inthe current stable version: 41. Gradie-based bull support Android-specific refactoring and quick fixes LUnt tools to catch performance, usability, version compatibility and other problems ProGuard integration and app-signing capabilities Tempate-based wirards to create common Android designs and components Arch layout editor that allows users to drag-and-drop UI components, option to preview layouts on multiple screen configurations Support for building Android Wear appe 8. Buln support for Google Cloud Platform, enabling integration with Firebase Cloud Messaging (Earlier Google Cloud ‘Messaging’ and Google App Engine 9. Android Virtual Device (Emulator to run and debug apps inthe Android studio. Inthe Weloame to Andboid Stadio window click Start «new Andeoid Studio projact you have a project already opened select File > New > New Project. In the Select a Project Template window, sect Empty Activity and click Nex. 4, Inthe Configure your project window, complete the following + Fates “My Pirst App" in the Name field + Enter “comexamplemyfrstapp" in the Package name field + If you'd like to place the project in a different folder, change its Save location + Select ether Java or Kotlin fiom the Language drop-down men, + Select the lowest version of Android you app wil sporti the Minimum SDK field + If your app will require legacy library support, mark the Use legacy androld.support brartes checkbox. + Leave the other options as they ae 5. Click Finish ‘After some processing time, the Android Stadio main window appears, [Now take a moment to review the mist important files, First, be se the Project widow is open (Selest View > Toot Windows > Project) and the Android view is selected ra the drop-down list atte top ofthat window. You can then se the Following ies: app > java > comexampleamyfirstapp > Main Activity ‘This isthe main activity, I's the eotry point for your app. When you build and un your app the system launches an stance ofthis Activity and loads its layout. app > res> layout > activty_main.xmal ‘This XML file defines the layout forthe actvity’s user interface (UD). It contains a TextView cloment with the txt “Hello, World! app > manifests> AndroidManifest.xml The manifest ile describes the fundamental characteristics ofthe app and defines each ofits componcs Grade Seripts> build grade There are (Wo files with this mame: one for the project, "Project: My First App.” and one for the app module, "Medule: app." Each module has its own build grade file, but this project currently has just one module. Use each module's bid grade file to contol how the Gradle plugin builds your spp, Cove: Main Activity kt Package con.oxanple.practical Import androidx.appeonpat -app-Appompatactivity import android. os.sundie class Wainactivity : AppCompatactivity() ( override fun onCreate (savedinstancestate: Bundle?) { super. onCreate (savedinstancestate) setContentView (R.layout-activity main} > , MainActiviyxml <®ml version="1.0" encodinga"utf-8" ?> cTextview android: layout_width="wrap_content’ android: layout_height="wrap_content”™ android:text="ello Guéran' app: layout_constraintBottom_toBottomof="parent™ app: layout_constraintLeft_toLeftof="parent" app: layout_constraintRight_toRightof="parent" app: layout_constraintTop_tofepof="parent" /> ‘Output ‘Conclusion [ve eamt how to create a project and make my own AVD to text my apps as pr standards to provide the test user ‘experience needed ‘Observation / Remarks The message has been displayed using Relative Layout Practical 2: Develop an android app to demonstrate Android Resources (Color Theme, Site, String, Image, Dravable, Dimension) —— ‘Theory: There are many more items which you use to build a good Android application. Apart from coding for the application, you ake cae of various ater resourees like static content that your code uses, such as bitmap, colors, layout definitions, user interface strings, animation instructions, and more. These resources are always maintained separately in various sub-directories under res directory ofthe project. Dinca and Resource Type: color: XML files tat define a stat is of colors. They are saved in resiclor/ and sevessedffom the Reo cass. 2 rabies tgs he pe pe ei on XML His hat are compiled it tap, tte Is tapes onation drawable, Tey ae saved in re/dravable’ and accessed from the R.dravable class 3. styles: A style resource defines the format and loa fora UL. A style can be applied to an individual View (Grom within 2 layout fle) or to an entie Activity or application (fem within the manifest fle). styls.xm for styles, accessed from Restye clas. 44 string A string resource provides text strings for your application with optional test styling and formatting, string xml for sing values snd accessed from R.sting las Cove: Main Activity kt Package con.oxanple.practical Import androidx.appeonpat -app-Appompatactivity import android. os.sundie class Halnactivity : Appcompatactivity() ( override fun onCreate(savedinstancestate: Bundle?) { super. onCreate (savedinstancestate) setContentView (R.layout-activity main} > , MainActiviyxml <2ml version="1.0" encoding="utf-8" ?> ctextview android: layout_width="natch_parent’ android: 1ayout_height="wrap_content” android:gravity="center" android: text="Hello Guérant android: textSize="24ep" /> android: 1d="9+4d/textview" android: 1ayout_width="natch parent" ayout_height="wrap_content” android:gravity=" center" android:text="Text color" android: textColor=" #FFIB39D8" android:textsize="24ap" /> id="g+id/textviews" layout_width="nateh parent" :layout_height="wrap_content"™ -avity="center" toxt="@string/roli_no" stextsizes"24sp" /> android: 1de"@+id/imageview" android: 1ayout_width="natch_parent’ android: layout_height="wrap_content” android: layout_gravity="center" app:srccompat="@mipmap/ic_launcher" /> 8color/colorPrinary 8color/color?rimaryDark ¢color/colorAccent Strings.xml cetring nano="app_nane'>MyPracticali string names"roll_no">1V1102 Colors.xml 4008577 #00574B 4031860 ‘Output Conclusion “These resources allow segregation of core properties ‘Observation / Remarks ‘The resources like colors, strings styles can be observed, Practical 3: Develop an android app to demonstrate Activity Life Cycle ‘Theory: The activity class provides a core st of 7 call backs 1. onCreate(: Caled by OS when the activity is first ereated. 2, onStart(: Called just after it's creation of by restart method after onStop(). Here Activity start becoming Visble to user. 13. onResumed): Called when Activity visible to user and User can interact with 4. onPause(): Called when Activity content is not Visible because user resume previous actvy 5. onStopQ: Called when activity is not visible to user because some other activity takes place of it 6. onRestartQ: Called when user comes on screen oF Fesume the activity which was stopped. 7. onDestroy0: Caled when Actity isnot in background, Cove: Main Activigkt Package con.exanple.pract import androidx.appcompat .app.AppCompatActivity import android.os.Sundie import android util-Log class Maindctivity : AppCompatActivity() override fun onCreate(savedinstancestate: Sundle?) { super onCreate (savedinstancestate) setContentView(R-layout activity main) print (YonCreate") ) override fon onstart () { ‘super.onstart () print (Yonstart") override fun onesume() ( certo sammncan super onkesume () print ("onResune”) ) override fun onPause () | ‘super.onPause () print (YonPause") ) override fun onkestart () | super.onfestart() print (YonRestart") ) override fun onstop() ( super. onstop() print ("onstop") ) override fun onDestroy() | super onbestroy() print (Yonbestroy") fun print msg: stringy c Log.d("activity state",nsa) , , Main Activityxad ‘output ‘Conclusion “Multiple activites, fragments allows code patton programming, Observation / Remarks The message as been displayed, Practical 4: Develop an android app to demonstrate Layoiit” Theory: Layout are sub-classes of view group which specifies how a view should be arranged inside the view groups. It defines the visual structure fora user interface. a. Linear Layout: It is a view group that aligns all children in a single direction vertically or horizontally. Layout direction is specified by android orientation attribute, b._ Relative Layout: It lays out elements based on their relationship with one another, and with the parent containers. c. Table Layout: It organizes content into rows and columns. Table layouts in android works in the same way HTML table layouts works 4. GridView Layout: GridView Layout shows items in 2 dimensional scrolling grid (rows and columns) and the grids items are not necessarily predetermined but they automatically inserted to layout using a list adapter. ©. ListView Layout: ListView is a view which groups several items and display them in vertical scrollable list. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database £. Frame Layout: Frame Layout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to di screen sizes without the children overlapping each other. 4a Linear Layout Conte: MainActivitykt Package con.oxanple.ayapplicationsa import androidx.appcompat .app-AppCompatactivity import android.oe.Sundio class Mainactivity : AppCompatactivity() ( override fun onCreate(savedinetancestate: Bundle?) { ‘super. onCreate (savedInstancestate) setContentView(R-layout activity main) MainActivity.xmt sree men curse ‘ ‘output ‘Conclusion “LinearLayout isa view group thet aligns all children ina single direction, vertically or horizontally. Observation / Remarks All Linear Layout ae stacked one after the other 4b Grid Layout Conte: MainActivitykt Package con.oxanple.ayapplicationsb import androidx.appcompat .app-AppCompatactivity import android.oe.Sundio class Maindctivity : AppCompatactivity() { override fun onCreate(savedinetancestate: Bundle?) { ‘super. onCreate (savedInstancestate) setContentView(R-layout activity main) MainActivityxmt “Linearlayout xalne:android="http://echanas.andeoid.con/apk/zee/android”™ alne!app="http: //schanas. android. con/apk/res~auto"™ salna:tools="hetp: //schemas-android.com/to0l" android: layout_width="nateh_ parent’ android: 1ayout_heaght="match parent tools:contaxt=" Mainactivity"> ‘android: layout_vidth="wrap_content™ Gndzoid:Layout_heaght="wrap content” android: text="llelio Gufran"/> android:ich"¢+ia/intton3" Android: layout_width="110dp" Shdreid:1ayoutpeight="10000" android: text="3" /> android:ich"¢ria/iuttont” Android: layout _width="110dp" Sndroid:1ayoutpeight="10000" anarosa:text=nd" /> android: ide" ¢+ia/buttons! Android: tayout_width="110ap" android: layout height="100dp" androsa:texe="5" />