Download presentation
Presentation is loading. Please wait.
Published byShanna Tyler Modified over 9 years ago
1
Activities Димитър Н. Димитров Astea Solutions AD
2
Recap: Android components Activity Service BroadcastReceiver ContentProvider Intent (?)
3
Starting an Android component – components can be started with Intents – Android creates the components and manages their lifecycle Application flow – in Java: everything starts from the main() method – in Android: no obligations for single entry point – pretty much everything you see in the application flow is managed by an Activity Applications and components
4
Activity “...a single, focused thing that the user can do.” creates a window and initializes the UI for it reacts on user interactions allows you to interact with the system functions and services – see android.content.Context
5
Activity lifecycle Activity states – resumed (running) – paused – stopped Lifecycle loops – entire lifetime – visible lifetime – foreground lifetime
6
Activity lifecycle Entire lifetime
7
Activity lifecycle Visible lifetime
8
Activity lifecycle Foreground lifetime
9
Activity lifecycle Activity is “killable” after: onPause() onStop() onDestroy() Two-Activity scenario: – A.onPause() – B.onCreate() – B.onStart() – B.onResume() – A.onStop() (already not visible)
10
android.app.Activity Starting an activity void startActivity(Intent intent)Intent void startActivityForResult(Intent intent, int requestCode)Intent – AndroidManifest.xml Important methods void setContentView() void onSaveInstanceState(Bundle)/void onRestoreInstanceState(Bundle)
11
Tasks Android groups Activities, started in order to perform a certain job in tasks – tasks are stacks (first in, first out) – clicking the hardware BACK button pops the current Activity from the stack, by default How many instances of a given Activity can I have? How can I start an Activity in a new task? What Activity will be resumed, when I press BACK?
12
Activities & your application All the different “screens” in your application should be different Activities – try not to put too much stuff in a single Activity Activities should encompass most of the business logic of your application – Activities act as a controller in the MVC pattern Start with a simple diagram and evolve it
13
Breaking news! Android 4.0 has just been released! It should bridge the gap between Android APIs for tablets and smartphones
14
Q&A + Feedback Questions? Feedback section: – Did you hear well? – Was there anything you didn’t understand? – What would you like changed in our next lecture?
15
Recommended resources http://developer.android.com/guide/topics/fundament als/activities.html http://developer.android.com/guide/topics/fundament als/activities.htm http://developer.android.com/guide/topics/fundament als/tasks-and-back-stack.html http://developer.android.com/guide/topics/fundament als/tasks-and-back-stack.html http://developer.android.com/guide/practices/ui_guid elines/activity_task_design.html http://developer.android.com/guide/practices/ui_guid elines/activity_task_design.html http://en.wikipedia.org/wiki/Model%E2%80%93view %E2%80%93controller http://en.wikipedia.org/wiki/Model%E2%80%93view %E2%80%93controller
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.