SlideShare a Scribd company logo
Introduction to  Android Programming 0 to “Hello World” in 60 minutes or less Silicon Valley China Wireless Group  Peter van der Linden [email_address] Android Technology Evangelist Developer Community Technical Services Motorola Mobility
Content Moore’s Law and mobile devices Android Software Development Checklist Ingredients of an App GUI basics Getting into code Running your code Q&A These slides are online at:  http://www.slideshare.net   account: pvdl01
Moore’s Law and Mobile Devices “ the number of transistors on an IC doubles approx every two years” Electronics Magazine, 19 April 1965 It’s the law - trend has continued for 45 years, and keeps going Trend is predictive of cpu Hz, storage size & speed, power consumption, network speed, etc etc Partly self-fulfilling, as it guides hw roadmaps
Smart Phone Family Tree PDA  cell phone  smart phone tablet netbook laptop Moore’s Law Moore’s  law Actual Family Tree
My Phone has 802.11 b/g/n Wifi 1 GHz CPU Moore’s Law This is not a toy. This is equivalent to a Windows XP PC  512 MB RAM bluetooth DVD quality video player Music quality audio USB port
My Droid X Phone ALSO has accelerometer Digital compass Moore’s Law Today’s  Windows PCs don’t have these …  HD video capture Voice phone with noise-canceling hw 8 MP camera Orientation sensors GPS receiver
Smart Phone Family Tree smart phone laptop Moore’s Law A more insightful way to think of it! = + more hw
Implications of HW capabilities Moore’s Law Expect the same characteristics as desktop apps Large and powerful API to choose from Development time and cost Plus need for great app graphics, icons, UI design The app sales channel problem is solved for you
2.  Android Software Checklist Embedded software development expertise Java Desktop SE expertise (who has Java cert?) Eclipse IDE expertise XML expertise SQL database programming expertise Open GL programming expertise The more of these you have,  the easier your learning curve will be
2.  Android Software Checklist Who has programmed in Java? Who has used any IDE? That’s enough to get started!
The SDK tool chain 5. Java runtime SE ver 6 4. Eclipse 3.5 3. Eclipse  ADT plug-in 2. Android SDK 1. Android Platform(s) Download  1,2,3, from developer.android.com 4 from Eclipse.org 5 from java.com
One stop shopping for Tools http:// developer.motorola.com/docstools/motodevstudio/download If you need to install Java runtime, it will tell you Versions for Windows, MacOS, Linux, 32 and 64 bit IDE for  all  Android on  all  platforms from  all  Manufacturers MOTODEV Studio
Compile time tools Java JRE Eclipse 3.5 Eclipse  ADT plug-in Android SDK Your code lives in Eclipse Your code is compiled by the SDK The Eclipse ADT plugin helps your code work with the Android SDK The Android SDK contains the Android libraries and tools
Runtime Development Tools Eclipse 3.5 Android SDK Android Platform You tell Eclipse to run your code Eclipse tells the emulator in the Android SDK The emulator contains the Android platform libraries. Emulator is an app on your PC that emulates Android hw Or use a real Android device over USB connection Emu
3.  Ingredients of an App Source code for every Android app has: Java  “ glue” XML, icons Media, data files, etc AndroidManifest.xml describes the app overall, features used, version, etc
Create app in Eclipse, by File > New > Android … Ingredients of an App, II
These folders and files are created, to start you off Ingredients of an App, III Java  “ glue” code XML, icons, etc Manifest.xml
Ingredients of an App, IV When you create a new app in Eclipse, you get: A complete set of files and folders, that form “Hello World”,  Including A Java source file An XML file (defines layout of components on the screen) Some generated “glue” code to make XML names visible to Java Some icons An overall AndroidManifest.xml file describing the app to the Android system
4.  GUI Basics Modern GUIs have common elements: Components (buttons, dialogs, progress bars, canvas, etc) Components are grouped and laid out by a layout manager LinearLayout Button TextView Press You can have text in a TextView Another Button
4.  GUI Basics Modern GUIs have common elements: Components generate events from user input.  You write & register callback routines to handle events Events are delivered to you on a UI thread (avoids the need for locking code in the GUI) Your code is called when needed  public class MyActivity extends Activity implements OnClickListener {           Button b= (Button) findViewById(R.id.pressme);         b.setOnClickListener(this);      . . .      // Implement the OnClickListener callback      public void onClick(View v) {        // actions when the button is clicked      }  
GUI Basics Android follows the conventional model in most respects One exception:  components and layout is in XML, not code Here’s what the XML looks like:  <Button>  some attributes=“values”  </Button> Usually shortened to this: <Button  some attributes=“values”  /> So your source is going to include a bunch of XML files
GUI Basics Your source includes a bunch of XML files
Getting into Code Every screen in your app is an Activity object that you code Your code extends android.app.Activity Every Activity has An XML file defining the GUI objects on its screen A Java file defining how user interacts with those objects And entry points that are called for you  at the right moments when something happens in the GUI (screen created, button pushed, etc)
Getting into Code, XML 1 An XML file defining the GUI objects on its screen General appearance: <?xml version= &quot;1.0&quot; encoding=&quot;utf-8&quot;?> <LinearLayout   … some attribute=“value” pairs …  > <TextView  … some attribute=“value” pairs …   /> </LinearLayout>
Getting into Code, XML 2 An XML file defining the GUI objects on its screen/Activity Full details <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; android:orientation=&quot;vertical&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent”  > <TextView  android:layout_width=&quot;fill_parent&quot;  android:layout_height=&quot;wrap_content&quot;  android:text=&quot;@string/hello”  /> </LinearLayout>
Getting into Code, XML 3 Every View must have a value for  android:layout_width  and  _height Tells layout manager how much room you want  for the WIDTH and the HEIGHT of the component &quot;fill_parent”  magic word that says “greedy – as much as possible”  &quot;wrap_content”  magic word that says “frugal – as little as possible” <TextView  android:layout_width= &quot;fill_parent&quot;  android:layout_height= &quot;wrap_content&quot;  android:text= &quot;@string/hello”  />
Getting into Code, XML 3 You can look at the screen this XML defines, in MOTODEV Studio
Getting into Code, II  The phases of an Activity  (the code for each screen goes thru these steps). Create (runs in the event loop until something stops it) Stop There are finer divisions within the phases, but this is the template You create methods to override the methods where you want to do something.  You want to override onCreate, and set up your GUI
Getting into Code, Activity 1 Java file defining interaction with GUI objects on screen General appearance: public class MainActivity extends android.app.Activity { /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);  // glue code! } }
Getting into Code, Activity 2 Java file defining interaction with GUI objects on screen Full details package com.motorola.hello2; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
Getting into Code, Glue The glue code is generated for you automatically Makes XML names in res folder, appear in Java namespace! This shows the convention for getting hold of layout files  under yourProject/res/layout setContentView(  R.layout.main  );  // says “use layout in file res/layout/main.xml”
Getting into Code, Glue 2 The glue code is generated for you Makes XML names in res folder, visible in Java namespace! Create  an ID name for an XML element with this attribute In Java, get hold  of that XML-declared TextView by:  In XML, get hold  of that XML-declared TextView by: TextView tv = (TextView)  findViewById( R.id.myTV ); <TextView  android:id=&quot;@+id/myTV &quot; <Button  android:layout_below= ”@id/myTV &quot;
Getting into Manifest AndroidManifest.xml – describes your app to the system < ?xml version= &quot;1.0&quot; encoding=&quot;utf-8&quot;?> <manifest xmlns:android= &quot;http://schemas.android.com/apk/res/android&quot; package= &quot;com.motorola.hello2&quot; android:versionCode= &quot;1&quot; android:versionName= &quot;1.0&quot;> <application android:icon= &quot;@drawable/icon&quot; android:label=&quot;@string/app_name&quot;> <activity android:name= &quot;.MainActivity&quot; android:label= &quot;@string/app_name&quot;> <intent-filter> <action android:name= &quot;android.intent.action.MAIN&quot; /> <category android:name= &quot;android.intent.category.LAUNCHER&quot; /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion= &quot;8&quot; /> </manifest>
Running your code Test your code on a sw emulator, or on a handset via USB The sw emulator runs on your development system.  It’s an app that emulates the hardware, and you load your test app onto it. Click “Run > Run as > Android Application” Live Demonstration of this
Follow-up developer.android.com –  Reference documentation –  Technical notes •  developer.motorola.com –  Technical Library –  Product Specs –  MOTODEV Studio –  Discussion Boards –  Blog posts –  and more …
Q & A Where to find more information: http://developer.motorola.com One stop shopping, with links to many other useful places One stop Tools and SDK download Tools that work for all Android devices from all manufacturers.
Apache 2 license Copyright (c) 2007-2010 by the  Android Open Source Project Licensed under the  Apache License, Version 2.0 (the &quot;License&quot;); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2010, Motorola, Inc. All  rights reserved. - Redistribution and use in source and binary forms, with or without  modification, are permitted provided that the following conditions are  met: -  Redistributions of source code must retain the above copyright notice, this  list of conditions and the following disclaimer. -  Redistributions in binary form must reproduce the above copyright notice, this  list of conditions and the following disclaimer in the documentation and/or  other materials provided with the distribution. -  Neither the name of the Motorola, Inc. nor the names of its contributors may  be used to endorse or promote products derived from this software without  specific prior written permission. BSD license
THIS  SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH  DAMAGE.   BSD license

More Related Content

What's hot (20)

ODP
Ci for Android
Alexey Ustenko
 
PPTX
Building your Own Mobile Enterprise Application: It’s Not as Hard as You Migh...
Jason Conger
 
PPTX
Introduction to Android and Android Studio
Suyash Srijan
 
PPT
Android application structure
Alexey Ustenko
 
PPTX
Android ppt
Pooja Garg
 
PPT
android-tutorial-for-beginner
Ajailal Parackal
 
PPTX
Android study jams 1
NancyMariaAS
 
PPTX
Android installation guide
Mohamed_Mubarak_Ali
 
PPTX
Android overview
Ahmed M. Abed
 
ZIP
Android Application Development
Benny Skogberg
 
PPTX
Arduino - Android Workshop Presentation
Hem Shrestha
 
PPT
Android Application Development Using Java
amaankhan
 
ODP
Introduction to Android App Development
Todd Burgess
 
PPTX
What’s new in aNdroid [Google I/O Extended Bangkok 2016]
Sittiphol Phanvilai
 
PDF
[Android] Introduction to Android Programming
Nikmesoft Ltd
 
PPT
Android overview
Alexey Ustenko
 
PPT
Android Seminar
Ganesh Waghmare
 
PPTX
Introduction_to_android_and_android_studio
Abdul Basit
 
PPT
Introduction to Android, Architecture & Components
Vijay Rastogi
 
PPTX
Selenium web driver_2.0_presentation
sayhi2sudarshan
 
Ci for Android
Alexey Ustenko
 
Building your Own Mobile Enterprise Application: It’s Not as Hard as You Migh...
Jason Conger
 
Introduction to Android and Android Studio
Suyash Srijan
 
Android application structure
Alexey Ustenko
 
Android ppt
Pooja Garg
 
android-tutorial-for-beginner
Ajailal Parackal
 
Android study jams 1
NancyMariaAS
 
Android installation guide
Mohamed_Mubarak_Ali
 
Android overview
Ahmed M. Abed
 
Android Application Development
Benny Skogberg
 
Arduino - Android Workshop Presentation
Hem Shrestha
 
Android Application Development Using Java
amaankhan
 
Introduction to Android App Development
Todd Burgess
 
What’s new in aNdroid [Google I/O Extended Bangkok 2016]
Sittiphol Phanvilai
 
[Android] Introduction to Android Programming
Nikmesoft Ltd
 
Android overview
Alexey Ustenko
 
Android Seminar
Ganesh Waghmare
 
Introduction_to_android_and_android_studio
Abdul Basit
 
Introduction to Android, Architecture & Components
Vijay Rastogi
 
Selenium web driver_2.0_presentation
sayhi2sudarshan
 

Similar to Intro to Android Programming (20)

PDF
Android Intro
Justin Grammens
 
PPT
Getting started with android dev and test perspective
Gunjan Kumar
 
PDF
Android 3.1 - Portland Code Camp 2011
sullis
 
PPT
Android presentation
Imam Raza
 
PPT
Android In A Nutshell
Ted Chien
 
PDF
Android 3.0 Portland Java User Group 2011-03-15
sullis
 
PPTX
Android Introduction on Java Forum Stuttgart 11
Lars Vogel
 
PDF
Android tutorial
Abid Khan
 
PPT
Introduction to Android Environment
Compare Infobase Limited
 
PPT
1 introduction of android
akila_mano
 
PDF
Android TCJUG
Justin Grammens
 
PPTX
Introduction to android
zeelpatel0504
 
PDF
Android - Open Source Bridge 2011
sullis
 
PPT
Lec005 android start_program
Eyad Almasri
 
PPT
Part 2 android application development 101
Michael Angelo Rivera
 
PPT
Industrial Training in Android Application
Arcadian Learning
 
PPTX
Android app development ppt
saitej15
 
PPTX
Android terminologies
jerry vasoya
 
PPTX
Android development-tutorial
ilias ahmed
 
PDF
Android dev o_auth
fantasy zheng
 
Android Intro
Justin Grammens
 
Getting started with android dev and test perspective
Gunjan Kumar
 
Android 3.1 - Portland Code Camp 2011
sullis
 
Android presentation
Imam Raza
 
Android In A Nutshell
Ted Chien
 
Android 3.0 Portland Java User Group 2011-03-15
sullis
 
Android Introduction on Java Forum Stuttgart 11
Lars Vogel
 
Android tutorial
Abid Khan
 
Introduction to Android Environment
Compare Infobase Limited
 
1 introduction of android
akila_mano
 
Android TCJUG
Justin Grammens
 
Introduction to android
zeelpatel0504
 
Android - Open Source Bridge 2011
sullis
 
Lec005 android start_program
Eyad Almasri
 
Part 2 android application development 101
Michael Angelo Rivera
 
Industrial Training in Android Application
Arcadian Learning
 
Android app development ppt
saitej15
 
Android terminologies
jerry vasoya
 
Android development-tutorial
ilias ahmed
 
Android dev o_auth
fantasy zheng
 
Ad

More from Peter van der Linden (8)

PDF
Grand finale
Peter van der Linden
 
PDF
Master cardapis v7.2020
Peter van der Linden
 
PDF
Master pass api
Peter van der Linden
 
PPT
Coding to the MasterCard OpenAPIs
Peter van der Linden
 
PDF
GDC 2014 talk Haptics Android
Peter van der Linden
 
PDF
Code to go Android
Peter van der Linden
 
PDF
Putting real feeling into Android Apps
Peter van der Linden
 
PDF
Droidcon berlin Apr2013
Peter van der Linden
 
Grand finale
Peter van der Linden
 
Master cardapis v7.2020
Peter van der Linden
 
Master pass api
Peter van der Linden
 
Coding to the MasterCard OpenAPIs
Peter van der Linden
 
GDC 2014 talk Haptics Android
Peter van der Linden
 
Code to go Android
Peter van der Linden
 
Putting real feeling into Android Apps
Peter van der Linden
 
Droidcon berlin Apr2013
Peter van der Linden
 
Ad

Intro to Android Programming

  • 1. Introduction to Android Programming 0 to “Hello World” in 60 minutes or less Silicon Valley China Wireless Group Peter van der Linden [email_address] Android Technology Evangelist Developer Community Technical Services Motorola Mobility
  • 2. Content Moore’s Law and mobile devices Android Software Development Checklist Ingredients of an App GUI basics Getting into code Running your code Q&A These slides are online at: http://www.slideshare.net account: pvdl01
  • 3. Moore’s Law and Mobile Devices “ the number of transistors on an IC doubles approx every two years” Electronics Magazine, 19 April 1965 It’s the law - trend has continued for 45 years, and keeps going Trend is predictive of cpu Hz, storage size & speed, power consumption, network speed, etc etc Partly self-fulfilling, as it guides hw roadmaps
  • 4. Smart Phone Family Tree PDA cell phone smart phone tablet netbook laptop Moore’s Law Moore’s law Actual Family Tree
  • 5. My Phone has 802.11 b/g/n Wifi 1 GHz CPU Moore’s Law This is not a toy. This is equivalent to a Windows XP PC 512 MB RAM bluetooth DVD quality video player Music quality audio USB port
  • 6. My Droid X Phone ALSO has accelerometer Digital compass Moore’s Law Today’s Windows PCs don’t have these … HD video capture Voice phone with noise-canceling hw 8 MP camera Orientation sensors GPS receiver
  • 7. Smart Phone Family Tree smart phone laptop Moore’s Law A more insightful way to think of it! = + more hw
  • 8. Implications of HW capabilities Moore’s Law Expect the same characteristics as desktop apps Large and powerful API to choose from Development time and cost Plus need for great app graphics, icons, UI design The app sales channel problem is solved for you
  • 9. 2. Android Software Checklist Embedded software development expertise Java Desktop SE expertise (who has Java cert?) Eclipse IDE expertise XML expertise SQL database programming expertise Open GL programming expertise The more of these you have, the easier your learning curve will be
  • 10. 2. Android Software Checklist Who has programmed in Java? Who has used any IDE? That’s enough to get started!
  • 11. The SDK tool chain 5. Java runtime SE ver 6 4. Eclipse 3.5 3. Eclipse ADT plug-in 2. Android SDK 1. Android Platform(s) Download 1,2,3, from developer.android.com 4 from Eclipse.org 5 from java.com
  • 12. One stop shopping for Tools http:// developer.motorola.com/docstools/motodevstudio/download If you need to install Java runtime, it will tell you Versions for Windows, MacOS, Linux, 32 and 64 bit IDE for all Android on all platforms from all Manufacturers MOTODEV Studio
  • 13. Compile time tools Java JRE Eclipse 3.5 Eclipse ADT plug-in Android SDK Your code lives in Eclipse Your code is compiled by the SDK The Eclipse ADT plugin helps your code work with the Android SDK The Android SDK contains the Android libraries and tools
  • 14. Runtime Development Tools Eclipse 3.5 Android SDK Android Platform You tell Eclipse to run your code Eclipse tells the emulator in the Android SDK The emulator contains the Android platform libraries. Emulator is an app on your PC that emulates Android hw Or use a real Android device over USB connection Emu
  • 15. 3. Ingredients of an App Source code for every Android app has: Java “ glue” XML, icons Media, data files, etc AndroidManifest.xml describes the app overall, features used, version, etc
  • 16. Create app in Eclipse, by File > New > Android … Ingredients of an App, II
  • 17. These folders and files are created, to start you off Ingredients of an App, III Java “ glue” code XML, icons, etc Manifest.xml
  • 18. Ingredients of an App, IV When you create a new app in Eclipse, you get: A complete set of files and folders, that form “Hello World”, Including A Java source file An XML file (defines layout of components on the screen) Some generated “glue” code to make XML names visible to Java Some icons An overall AndroidManifest.xml file describing the app to the Android system
  • 19. 4. GUI Basics Modern GUIs have common elements: Components (buttons, dialogs, progress bars, canvas, etc) Components are grouped and laid out by a layout manager LinearLayout Button TextView Press You can have text in a TextView Another Button
  • 20. 4. GUI Basics Modern GUIs have common elements: Components generate events from user input. You write & register callback routines to handle events Events are delivered to you on a UI thread (avoids the need for locking code in the GUI) Your code is called when needed  public class MyActivity extends Activity implements OnClickListener {           Button b= (Button) findViewById(R.id.pressme);         b.setOnClickListener(this);     . . .     // Implement the OnClickListener callback     public void onClick(View v) {       // actions when the button is clicked     }  
  • 21. GUI Basics Android follows the conventional model in most respects One exception: components and layout is in XML, not code Here’s what the XML looks like: <Button> some attributes=“values” </Button> Usually shortened to this: <Button some attributes=“values” /> So your source is going to include a bunch of XML files
  • 22. GUI Basics Your source includes a bunch of XML files
  • 23. Getting into Code Every screen in your app is an Activity object that you code Your code extends android.app.Activity Every Activity has An XML file defining the GUI objects on its screen A Java file defining how user interacts with those objects And entry points that are called for you at the right moments when something happens in the GUI (screen created, button pushed, etc)
  • 24. Getting into Code, XML 1 An XML file defining the GUI objects on its screen General appearance: <?xml version= &quot;1.0&quot; encoding=&quot;utf-8&quot;?> <LinearLayout … some attribute=“value” pairs … > <TextView … some attribute=“value” pairs … /> </LinearLayout>
  • 25. Getting into Code, XML 2 An XML file defining the GUI objects on its screen/Activity Full details <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; android:orientation=&quot;vertical&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent” > <TextView android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;@string/hello” /> </LinearLayout>
  • 26. Getting into Code, XML 3 Every View must have a value for android:layout_width and _height Tells layout manager how much room you want for the WIDTH and the HEIGHT of the component &quot;fill_parent” magic word that says “greedy – as much as possible” &quot;wrap_content” magic word that says “frugal – as little as possible” <TextView android:layout_width= &quot;fill_parent&quot; android:layout_height= &quot;wrap_content&quot; android:text= &quot;@string/hello” />
  • 27. Getting into Code, XML 3 You can look at the screen this XML defines, in MOTODEV Studio
  • 28. Getting into Code, II The phases of an Activity (the code for each screen goes thru these steps). Create (runs in the event loop until something stops it) Stop There are finer divisions within the phases, but this is the template You create methods to override the methods where you want to do something. You want to override onCreate, and set up your GUI
  • 29. Getting into Code, Activity 1 Java file defining interaction with GUI objects on screen General appearance: public class MainActivity extends android.app.Activity { /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // glue code! } }
  • 30. Getting into Code, Activity 2 Java file defining interaction with GUI objects on screen Full details package com.motorola.hello2; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
  • 31. Getting into Code, Glue The glue code is generated for you automatically Makes XML names in res folder, appear in Java namespace! This shows the convention for getting hold of layout files under yourProject/res/layout setContentView( R.layout.main ); // says “use layout in file res/layout/main.xml”
  • 32. Getting into Code, Glue 2 The glue code is generated for you Makes XML names in res folder, visible in Java namespace! Create an ID name for an XML element with this attribute In Java, get hold of that XML-declared TextView by: In XML, get hold of that XML-declared TextView by: TextView tv = (TextView) findViewById( R.id.myTV ); <TextView android:id=&quot;@+id/myTV &quot; <Button android:layout_below= ”@id/myTV &quot;
  • 33. Getting into Manifest AndroidManifest.xml – describes your app to the system < ?xml version= &quot;1.0&quot; encoding=&quot;utf-8&quot;?> <manifest xmlns:android= &quot;http://schemas.android.com/apk/res/android&quot; package= &quot;com.motorola.hello2&quot; android:versionCode= &quot;1&quot; android:versionName= &quot;1.0&quot;> <application android:icon= &quot;@drawable/icon&quot; android:label=&quot;@string/app_name&quot;> <activity android:name= &quot;.MainActivity&quot; android:label= &quot;@string/app_name&quot;> <intent-filter> <action android:name= &quot;android.intent.action.MAIN&quot; /> <category android:name= &quot;android.intent.category.LAUNCHER&quot; /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion= &quot;8&quot; /> </manifest>
  • 34. Running your code Test your code on a sw emulator, or on a handset via USB The sw emulator runs on your development system. It’s an app that emulates the hardware, and you load your test app onto it. Click “Run > Run as > Android Application” Live Demonstration of this
  • 35. Follow-up developer.android.com – Reference documentation – Technical notes • developer.motorola.com – Technical Library – Product Specs – MOTODEV Studio – Discussion Boards – Blog posts – and more …
  • 36. Q & A Where to find more information: http://developer.motorola.com One stop shopping, with links to many other useful places One stop Tools and SDK download Tools that work for all Android devices from all manufacturers.
  • 37. Apache 2 license Copyright (c) 2007-2010 by the Android Open Source Project Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  • 38. Copyright (c) 2010, Motorola, Inc. All  rights reserved. - Redistribution and use in source and binary forms, with or without  modification, are permitted provided that the following conditions are  met: -  Redistributions of source code must retain the above copyright notice, this  list of conditions and the following disclaimer. -  Redistributions in binary form must reproduce the above copyright notice, this  list of conditions and the following disclaimer in the documentation and/or  other materials provided with the distribution. -  Neither the name of the Motorola, Inc. nor the names of its contributors may  be used to endorse or promote products derived from this software without  specific prior written permission. BSD license
  • 39. THIS  SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH  DAMAGE. BSD license