Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to Android


Published on

  • Be the first to comment

  • Be the first to like this

Introduction to Android

  1. 1. Introduction to Android
  2. 2. Challenges • Small screens • CPU memory and speed are tight • Programming languages and frameworks are dependent on the device manufacturer’s support • Applications must not interfere with phone system
  3. 3. Android • Eclipse development • Java programming language • Framework for phone applications • Every application runs in its own Linux process
  4. 4. Android Components • Activity – Similar to a window or dialog in a desktop application – Each activity is given a default window to draw in – An application may consist of one or more activities – Visual content is provided by a hierarch of View objects • Content Provider – Provides access to data
  5. 5. Android Components • Services – Long running applications such as checking for updates on an RSS feed • Broadcast Receiver – Receives and reacts to broadcast announcements such as battery low, picture taken – Extend BroadcastReceiver base class – Can start an activity in response to information or use the NotificationManager to aler the user through vibrating the device, playing a sound, etc.
  6. 6. Intent • Asynchronous messages • Intent object holds the content of the message – Activities are launched or activated by papassing an Intent object to Context.startActivity – Services are started by passing an Intent object ot Context.startService() – A broadcast can be initiated by passing an Intent object to Context.sendBroadcast()
  7. 7. AndroidManifest.xml • Describes the application and the components available – <activity>, <service>, and <receiver> tags • Names libraries needed • Identifies permissions the application expects to be granted <?xml version="1.0" encoding="utf-8"?> <manifest . . . > <application . . . > <activity android:name="com.example.project.FreneticActivity" android:icon="@drawable/small_pic.png" android:label="@string/freneticLabel" ... > </activity> ... </application> </manifest>
  8. 8. Saying Hello to the World • Create an Android Virtual Device (AVD) – Choose Window->Android SDK and AVD Manager – Select Virtual Devices in the left panel – Click New, the Create New AVD dialog appears – Type the name of the AVD such as “my_avd” – Choose a target – Click Create AVD
  9. 9. Saying Hello to the World • Create a New Android Project – Select File->New->Project->Android – Select “Android Project” and click Next – Fill in the Project Details: • Project Name: HelloAndroid • Application Name: Hello, Android • Package Name: edu.adams.cs250 • Create Activity: HelloAndroid – Click Finish
  10. 10. HelloAndroid Called when Android •User interacts with one Activity at a time. starts the Activity •Not required to have a UI but it usually does public class HelloAndroid extends Activity { public void onCreate( Bundle savedInstanceState ){ super.onCreate(savedInstanceState); setContentView( R.layout.main); } }
  11. 11. Saying Hello to the World • Add view objects – Drawable objects that •An Activity inherits from Context are subclasses of View •A Context is a handle to the system that can be used to obtain access to databases and user preferences TextView tv = new TextView( this ); tv.setText( “Hello, Android”); setContentView( tv ); Sets the view for the Activity
  12. 12. XML Layout • Programmatic UI can be time-consuming to build •Save in res/layout/main.xml •For landscape layout, save • Difficult to change the file in res/layout-land <TextView xmlns:android= android:layout_width=“fill_parent” •How much of the screen width android:layout_height=“fill_parent” the view should consume •Since it is the only view, it will android:text=“@string/hello”/> take up the entire screen •The resource to use to find the text of the button •File is located in res/values/strings.xml •Provides internationalization support
  13. 13. Strings.xml <resources> <string name=“hello”>Hello Android!</string> <string name=“app_name”>Hello, Android</string> </resources>
  14. 14. Activity Modification public void onCreate( Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); }