【正文】
選擇。在這個例子中, intent filter 能找到 Email、 Gmail、 Messaging、Picasa 等。 啟動一個 activity 并需要返回一個結(jié)果 官方稱這種方式為 closed loop,也就是說當啟動一個 activity 之后,會返回一個結(jié)果回來。這個例子中的上傳過程所用到的 activity 就是由外部的 Gallery 啟動的。舉個例子,在 Email 中可定位一個住址,那么應(yīng)用程序便會啟動地圖 activity 來定位地址,完成之后不會再給 Email 返回任何的結(jié)果;此時用戶可以按 BACK 鍵回到 Email 中來。我們甚至還可以讓其內(nèi)部存在兩個主 activity,也就是兩個應(yīng)用程序啟動入口點。它們都共享使用一個鏡頭、在 Gallery 里面保存圖片等。(每個 activity都其各自的任務(wù),每個任務(wù)都有不同的親緣性 (affinity)。 聯(lián)系人和撥號器也是同一個應(yīng)用兩個主 activity 的典型例子。 允許你的 activity 添加到當前任務(wù)中 如果你的 activity 是在外部應(yīng)用程序 已經(jīng)啟動的話,那么也允許把它們添加到當前的任務(wù)中來(或者是已存在的任務(wù) —— 它有自身的 affinity),這樣做的話能會使用戶能夠在其它任務(wù)和你的 activity 之間進行自由切換。 對于這種行為,你的 activity 應(yīng)該有一個 standard 或 singleTop 的啟動模式,而不是 singleTask 或 singleInstance,這樣,你的 activity 就會以多實例的模式來運行。這兩個會直接彈出來提示用戶,再說通俗一些就是會突然打斷用戶的當前操作,這是一個極為不友好的用戶體驗。 不要重新設(shè)置 BACK 鍵的功能,除非你有絕對的需要 BACK 鍵的主要功能就是從當前的 activity 回退到上一個 activity,就是所謂的導(dǎo)航功能。 但要考慮一個問題,如果是應(yīng)用程序非常得大,并需要細粒度的 BACK 鍵來加以控制該如何呢?例如 Google 瀏覽器,已經(jīng)打開了幾個 web 頁面和地圖頁面,其中有一些關(guān)于地圖數(shù)據(jù)的圖層面板,我們需要在它們之間進行切換操作,也就是說在其內(nèi)部通過 BACK 鍵來對其進行回退導(dǎo)航,而不是針對整體的 activity。地圖應(yīng)用 程序?qū)⑦@些圖層面板保存在自身的歷史記錄里面,所以需要 BACK 鍵來進行回退導(dǎo)航。例如,你在 Android 瀏覽器中的一個窗體上打開 Google 進行查詢,并點擊一條查詢結(jié)果,那么這個結(jié)果頁面會在當前窗體上打開,然后按 BACK 鍵就會回到了查詢頁面。如果用戶一直按 BACK 鍵的話,最后就會離開瀏覽器所在的 activity,回到了桌面。 東北大學 東軟信息學院畢業(yè)設(shè)計(論文) 譯文 6 Activity and Task Design This document describes core principles of the Android application framework, from a highlevel, usercentric perspective useful to interaction and application designers as well as application developers. It illustrates activities and tasks with examples, and describes some of their underlying principles and mechanisms, such as navigation, multitasking, activity reuse, intents, and the activity stack. The document also highlights design decisions that are available to you and what control they give you over the UI of your application. This document draws examples from several Android applications, including default applications (such as Dialer) and Google applications (such as Maps). You can try out the examples yourself in the Android emulator or on an Androidpowered device. If you are using a device, note that your device may not offer all of the example applications used in this document. Applications, Activities, Activity Stack and Tasks Four fundamental concepts in the Android system that are helpful for you to understand are: Applications Activities Activity Stack Tasks Applications An Android application 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 that may include , calendar, browser, maps, text messaging, contacts, camera, dialer, music player, settings and others. Android has an application launcher available at the Home screen, typically in a sliding drawer which displays applications as icons, which the user can pick to start an application. Activities 東北大學 東軟信息學院畢業(yè)設(shè)計(論文) 譯文 7 Activities are the main building blocks of Android applications. When you create an application, you can assemble it from activities that you create and from activities you reuse from other applications. These activities are bound at runtime, so that newly installed applications can take advantage of already installed activities. Once assembled, activities work together to form a cohesive user interface. An activity has a distinct visual user interface designed around a single, wellbounded purpose, such as viewing, editing, dialing the phone, taking a photo, searching, sending data, starting a voice mand, or performing some other type of user action. Any application that presents anything on the display must have at least one activity responsible for that display. When using an Android device, as the user moves through the user interface they start activities one after the other, totally oblivious to the underlying behavior — to them the experience should be seamless, activity after activity, task after task. An activity handles a particular type of content (data) and accepts a set of related user actions. Each activity has a lifecycle that is independent of the other activities in its application or task — each activity is launched (started) independently, and the user or system can start, run, pause, resume, stop and restart it as needed. Because of this independence, activities can be reused and replaced by other activities in a variety of ways. An activity is the most prominent of four ponents of an application. The other ponents are service, content provider and broadcast receiver. Activity Stack As the user moves from activity to activity, across applications, the Android system keeps a linear navigation history of activities the user has visited. This is the activity stack, also known as the back stack. In general, 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 key to go back further than the last visit to Home. The adding of an activity to the current stack happens whether or not that activity begins a new task (as long as that task was started without going Home), so going back can let the user go back to activities in previous tasks. The user can get to tasks earlier than the most recent Home by selecting its root activity from the application launcher, a shortcut, or the Recent tasks screen. Activities are the only things that can be added to the activity stack — views, windows, menus, and dialogs cannot. That is, when designing the navigation, if you have screen A and you want the user