Bài giảng Lập trình cho thiết bị di động - Bài 1: Giới thiệu môi trường phát triển điện thoại di động
1.1 Topics
1.2 Learning Objectives
1.3 Textbooks
1.4 Test / Grade
1.5 Assignments
1.6 Rules
Tóm tắt nội dung Bài giảng Lập trình cho thiết bị di động - Bài 1: Giới thiệu môi trường phát triển điện thoại di động, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
The quantity of pixels within a physical area of the screen - dpi (dots per inch): low, medium, high, and extra high. Orientation: landscape or portrait Resolution: The total number of physical pixels on a screen. app do not work directly with resolution; concerned only with screen size and density 99 8.1 Screen Density-independent pixel (dp) : A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way. 100 8.2 Units of measurement In Inches - based on the physical size of the screen Mm Millimeters - based on the physical size of the screen. Pt Points - 1/72 of an inch based on the physical size of the screen. Px Pixels - corresponds to actual pixels on the screen Dip /Dp Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Sp/sip Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference. 101 8.2 Units of measurement try to never use anything but sp or dp unless you absolutely have to. Using sp/dp will make your Android applications compatible with multiple screen densities and resolutions you want to use sp for font sizes and dip for everything else. 102 8.3 Example Example of two screens that are the same size, diff resolution: 103 8.3 Example app without support for different densities vs density independent 104 Screen Sizes and Densities distribution: Data collected during a 7-day period ending on September 4, 2013 105 Platform version distribution: 106 9. XML Primer XML in Android: Layout, Menu, Value, Manifest … Please visit the link below to learn more XML: Please visit the link below to parse xml data: 107 10. Application’s Life Cycle 10.1 Applications 10.2 Activities 10.3 Activity Stack 10.4 Tasks 10.5 Life Cycle States 108 10.1 Applications typically consists of one or more related, loosely bound activities for the user to interact with, typically bundled up in a single file (with an .apk suffix). Android ships with a rich set of applications:email, calendar, browser, maps, text messaging, contacts, camera, dialer, music player…. Android has an application launcher available at the Home screen 109 10.2 Activities main building blocks of Android applications Each activity has a lifecycle that is independent of the other activities in its application or task each activity is launched (started) independently, user or system can start, run, pause, resume, stop and restart it as needed. can be re-used and replaced by other activities in a variety of ways. 110 10.3 Activity Stack Activities in the system are managed as an activity stack. keeps a linear navigation history of activities the user has visited when a user starts a new activity, it is added to the activity stack, so that pressing Back displays the previous activity on the stack. However, the user cannot use the Back button to go back further than the last visit to Home. Activities are the only things that can be added to the activity stack — views, windows, menus, and dialogs cannot. 111 10.3 Activity Stack 112 10.4 Tasks sequence of activities the user follows to accomplish an objective, regardless of which applications the activities belong to The activity that starts a task is called the root activity spanning multiple processes Interrupting the Task by a notification Home button How Multitasking with Task? 113 Activities vs Task 114 10.5 Life Cycle States An activity has essentially three states: 1. It is active or running 2. It is paused or 3. It is stopped . 115 10.5 Life Cycle States Running It is active or running when it is in the foreground of the screen (at the top of the activity stack for the current task). This is the activity that is the focus for the user's actions. 116 10.5 Life Cycle States Paused It is paused if it has lost focus but is still visible to the user. That is, another activity lies on top of it and that new activity either is transparent or doesn't cover the full screen. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations. 117 10.5 Life Cycle States Stopped It is stopped if it is completely obscured by another activity. It still retains all state and member information. However, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere. 118 10.5 Life Cycle States Application’s Life Cycle 119 10.5 Life Cycle States Demo Application’s Life Cycle 120 10.5 Life Cycle States Visible Lifetime Foreground Lifetime 121 10.5 Life Cycle States Visible Lifetime The visible lifetime of an activity happens between a call to onStart() until a corresponding call to onStop(). During this time, the user can see the activity on‐screen, though it may not be in the foreground and interacting with the user. The onStart() and onStop() methods can be called multiple times, as the activity alternates between being visible and hidden to the user. Between these two methods, you can maintain resources that are needed to show the activity to the user. 122 10.5 Life Cycle States Foreground Lifetime The foreground lifetime of an activity happens between a call to onResume() until a corresponding call to onPause(). During this time, the activity is in front of all other activities on screen and is interacting with the user. An activity can frequently transition between the resumed and paused states — for example, onPause() is called when the device goes to sleep or when a new activity is started, onResume() is called when an activity result or a new intent is delivered. 123 10.5 Life Cycle States Method: onCreate() Called when the activity is first created. This is where you should do all of your normal static set up —create views, bind data to lists, and so on. This method is passed a Bundle object containing the activity's previous state, if that state was captured. Always followed by onStart() 124 10.5 Life Cycle States Method: onRestart() Called after the activity has been stopped, just prior to it being started again. Always followed by onStart() Method: onStart() Called just before the activity becomes visible to the user. Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden. 125 10.5 Life Cycle States Method: onResume() 1. Called just before the activity starts interacting with the user. 2. At this point the activity is at the top of the activity stack, with user input going to it. 3. Always followed by onPause(). 126 10.5 Life Cycle States Method: onPause() 1. Called when the system is about to start resuming another activity. 2. This method is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, and so on. 3. It should do whatever it does very quickly, because the next activity will not be resumed until it returns. 4. Followed either by onResume() if the activity returns back to the front, or by onStop() if it becomes invisible to the user. 5. The activity in this state is killable by the system. 127 10.5 Life Cycle States Method: onStop() 1. Called when the activity is no longer visible to the user. 2. This may happen because it is being destroyed, or because another activity (either an existing one or a new one) has been resumed and is covering it. 3. Followed either by onRestart() if the activity is coming back to interact with the user, or by onDestroy() if this activity is going away. 4. The activity in this state is killable by the system. 128 10.5 Life Cycle States Method: onDestroy() 1. Called before the activity is destroyed. 2. This is the final call that the activity will receive. 3. It could be called either because the activity is finishing (someone called finish() on it), or because the system is temporarily destroying this instance of the activity to save space. 4. The activity in this state is killable by the system. 129 10.5 Life Cycle States Killable States Activities on killable states can be terminated by the system at any time after the method returns, without executing another line of the activity's code. Three methods (onPause(), onStop(), and onDestroy()) are killable. onPause() is the only one that is guaranteed to be called before the process is killed —onStop() and onDestroy() may not be. Therefore, you should use onPause() to write any persistent data (such as user edits) to storage. 130 10.5 Life Cycle States We should write and read data for application’s sate in methods: onPause() and (onCreate() or onResume()) by SharedPreferences 131 10.5 Life Cycle States Android Preferences Preferences is a lightweight mechanism to store and retrieve key‐value pairs of primitive data types. It is typically used to store application preferences, such as a default greeting or a text font to be loaded whenever the application is started. Call Context.getSharedPreferences() to read and write values. Assign a name to your set of preferences if you want to share them with other components in the same application, or use Activity.getPreferences() with no name to keep them private to the calling activity. getSharedPreferences() - can be used while using multiple preference files and getPreferences() - can be used for only one preference file(default) for that specific activity. File xml You cannot share preferences across applications (except by using a content provider). 132 GOOGLE PLAY END 133
File đính kèm:
- 1 - GIỚI THIỆU MÔI TRƯỜNG PHÁT TRIỂN ĐIỆN THOẠI DI ĐỘNG.pptx