Project a day 2   android application fundamentals
Upcoming SlideShare
Loading in...5

Project a day 2 android application fundamentals






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Project a day 2   android application fundamentals Project a day 2 android application fundamentals Presentation Transcript

  • Android Application Fundamentals
  • Android concepts • Activity – visual user interface focused on a single thing a user can do • Service – no visual interface – they run in the background • Broadcast receiver – receive and react to broadcast announcements • Content provider – allow data exchange between applications • Intent • Manifest 2
  • Applications • Written in Java • Lunching an application makes it the root of a task (not equal task) • Each application runs in its own process • Each process has its own separate VM • Each application is assigned a unique Linux user ID – by default files of that application are only visible to that application (can be explicitly exported) • Android manages memory by process prioritization and it has a license to kill  3
  • Activities • Basic component of most applications • Most applications have several activities that start each other as needed • Task is a set of Activities arranged in a stack (example Gmail app) • Stack is independent • Each is implemented as a subclass of the base Activity class • Activities can belong to a process that is killed (what to do then?) 4
  • Understanding the lifecycle 5
  • Activity states • Running state • Activity is in the foreground • Full access to resource • Will not be destroyed • Paused state • • • • Activity is visible but not in the foreground Retains memory resources Limited opportunity to perform processing Not likely to be destroyed • Stopped state • • • • Activity is not visible Should be prepared to lose memory resources Limited opportunity to perform processing Very likely to be destroyed 6
  • Activities – The View • Each activity has a default window to draw in (although it may prompt for dialogs or notifications) • The content of the window is a view or a group of views (derived from View or ViewGroup) • Example of views: buttons, text fields, scroll bars, menu items, check boxes, etc. • View(Group) made visible via Activity.setContentView() method. 7
  • Activity DEMO • Activity Lifecycle • Getting Views from the Layout • Menu handling 8
  • Option menu 9
  • Options menu 10
  • Options menu 11
  • Activity • Activities use methods and resources do describe menus and layout • Menu items normally have at least an id and a title • Use string resource to avoid literal strings • Prefer the onOptionItemSelected method over the onClick Method • All activities must be defined in manifest • Activities are displayed with startActivity method (with intent) • Each Activity manages its own menu • Activity life time is not the same as process life time 12
  • Views and Layouts • The role of Views and Layouts • Using Layouts • Linear Layout • Relative Layout • Handling View event Callback 13
  • The role of Views and Layouts • Android UI is composed of Layouts and Views • Views are UI components • ViewGroups are Views that hold othe Views • Layouts are specialized ViewGroups • Describe View positioning • A Layout is commonly the root of the UI • Layouts are often layered within one another • You can construct your UI using resource or the code 14
  • Views are positioned based on its parent layout 15
  • Using Layouts • Linear Layout Layout_gravity = left/right Layout_weight = number Gravity affects content and layout gravity affects controll • Relative Layout Relative to other control (based on id) and/or parent • Grid Layout • • • • • • RolumCount RowCount Layout_row Layout_column Layout_rowSpan Layout_columnSpan 16
  • Layout DEMO 17
  • Services • Does not have a visual interface • Runs in the background indefinitely • Examples • Network Downloads • Playing Music • TCP/UDP Server • You can bind to a an existing service and control its operation 18
  • Broadcast Receivers • Receive and react to broadcast announcements • Extend the class BroadcastReceiver • Examples of broadcasts: • Low battery, power connected, shutdown, timezone changed, etc. • Other applications can initiate broadcasts 19
  • Content Providers • Makes some of the application data available to other applications • It’s the only way to transfer data between applications in Android (no shared files, shared memory, pipes, etc.) • Extends the class ContentProvider; • Other applications use a ContentResolver object to access the data provided via a ContentProvider 20
  • Intents • An intent is an Intent object with a message content. • Activities, services and broadcast receivers are started by intents. ContentProviders are started by ContentResolvers 21
  • Shutting down components • Activities • Can terminate itself via finish(); • Can terminate other activities it started via finishActivity(); • Services • Can terminate via stopSelf(); or Context.stopService(); • Content Providers • Are only active when responding to ContentResolvers • Broadcast Receivers • Are only active when responding to broadcasts 22
  • Android Manifest • Its main purpose in life is to declare the components to the system: <?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> 23
  • Android Manifest • Version ID and Version name • Application settings • Permissions • Instrumentation • Use the XML view 24