Project a day 2 android application fundamentals

375 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
375
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Project a day 2 android application fundamentals

  1. 1. Android Application Fundamentals
  2. 2. 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
  3. 3. 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
  4. 4. 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
  5. 5. Understanding the lifecycle 5
  6. 6. 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
  7. 7. 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
  8. 8. Activity DEMO • Activity Lifecycle • Getting Views from the Layout • Menu handling 8
  9. 9. Option menu 9
  10. 10. Options menu 10
  11. 11. Options menu 11
  12. 12. 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
  13. 13. Views and Layouts • The role of Views and Layouts • Using Layouts • Linear Layout • Relative Layout • Handling View event Callback 13
  14. 14. 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
  15. 15. Views are positioned based on its parent layout 15
  16. 16. 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
  17. 17. Layout DEMO 17
  18. 18. 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
  19. 19. 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
  20. 20. 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
  21. 21. 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
  22. 22. 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
  23. 23. 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
  24. 24. Android Manifest • Version ID and Version name • Application settings • Permissions • Instrumentation • Use the XML view 24
  25. 25. ANY QUESTIONS? 25

×