• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Introduction to Android
 

Introduction to Android

on

  • 838 views

 

Statistics

Views

Total Views
838
Views on SlideShare
838
Embed Views
0

Actions

Likes
0
Downloads
19
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

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
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Introduction to Android Introduction to Android Presentation Transcript

    • Introduction to Android
    • 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
    • Android • Eclipse development • Java programming language • Framework for phone applications • Every application runs in its own Linux process
    • 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
    • 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.
    • 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()
    • 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>
    • 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
    • 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
    • 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); } }
    • 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
    • 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=http://schemas.android.com/apk/res/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
    • Strings.xml <resources> <string name=“hello”>Hello Android!</string> <string name=“app_name”>Hello, Android</string> </resources>
    • Activity Modification public void onCreate( Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); }