android activity
play

Android Activity CS 4720 Mobile Application Development Source: - PowerPoint PPT Presentation

Android Activity CS 4720 Mobile Application Development Source: developer.android.com CS 4720 Activity Conceptually, an Activity is a single screen of your application In other words, an App really is a collection of related


  1. Android Activity CS 4720 – Mobile Application Development Source: developer.android.com CS 4720

  2. Activity • Conceptually, an Activity is a single screen of your application • In other words, an App really is a collection of related Activities • Consider each Activity both a screen and a feature • Apps can activate Activities in other Apps CS 4720 2

  3. The App Lifecycle CS 4720 3

  4. The Activity CS 4720 4

  5. The Lifecycle • An Activity can be: – Resumed – active and in the foreground with user focus – Paused – active, but is “covered up” by another activity that currently has the user focus – Stopped – currently residing in the background and is not attached to the window manager and is not visible; can be killed by system if memory is needed CS 4720 5

  6. Lifecycle Callbacks CS 4720 6

  7. Lifecycle Callbacks • Make sure to make the correct calls in the correct methods! • If you do everything in onCreate(), then problems could occur when you switch • On a device rotation, onDestroy() / onCreate() is called • Consider saving state using onSaveInstanceState() to retain App state between switching CS 4720 7

  8. onCreate() • Called when App is starting fresh • This is where setContentView() (setting the UI) is called • This is why onCreate() is called on a rotation – you may be using a different layout CS 4720 8

  9. Next Steps • onStart() - Called right before Activity is shown to user • onResume() – Called just before Activity will start accepting user input • onPause() – Called when another Activity will call onResume() – used to save remaining changes • onStop() – Called when Activity is no longer visible CS 4720 9

  10. UI • UI components come from the View class • A View controls a set of rectangular space and can respond to user interaction • Can be the whole screen, or just a small portion • Technically, a “widget” (like a button) is a very small View • A Layout (and it’s xml) is a group of Views with location instructions CS 4720 10

  11. Adding to the Manifest • All Activities must be defined in the androidmanifest.xml file • Intents that this Activity can respond to are also defined here CS 4720 11

  12. Launching a new Activity • To launch a new Activity, create an Intent for that Activity and send it out CS 4720 12

  13. Fragments • Consider a Fragment a sort of “sub-Activity” • An Activity can be made up of numerous Fragments, each with their own features • This is useful when you want to move/reorder components for different display sizes/rotations • A Fragment obeys the Activity’s lifecycle state CS 4720 13

  14. Fragments CS 4720 14

  15. Fragments • A Fragment has: – Its own lifecycle calls – Its own layouts – Its own views • In fact, a Fragment looks almost exactly like an Activity! • To add a Fragment, instantiate it in the layout of the Activity CS 4720 15

  16. FragmentManager • The main benefits Fragments are reusability and addressability • Fragments can be accessed through the FragmentManager and can be swapped on the fly while the App is running • Fragments can address the Activity that contains them, allowing for sharing of data between Fragments CS 4720 16

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend