移動互聯(lián)網(wǎng)課考的是安卓。。。作為iOS程序員建立了一下對應(yīng)關(guān)系。。。不知道能不能過=。=
- Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications.
- It's possible to arrange for two applications to share the same Linux user ID, in which case they are able to access each other's files. To conserve system resources, applications with the same user ID can also arrange to run in the same Linux process and share the same VM (the applications must also be signed with the same certificate).
- A central feature of Android is that one application can make use of elements of other applications (provided those applications permit it).
- Activities
- Services
- Broadcast receivers
- Content providers
- 安卓能通過Content providers 共享數(shù)據(jù),不像iOS只能copy一份
- Broadcast Receiver 與 iOS 中的NSNotificationCenter略有不同 還能喚醒App真是666,終于知道百度全家桶的由來
- 安卓中activity有返回值嗎?(用別的App拍照返回照片)
- 有的,通過Intent傳回
- 優(yōu)點:低耦合
- 缺點:類型不安全,其實還是存在耦合(需要提前知道類型)
- 安卓用其它應(yīng)用的Activity時其實新開了一個進程,那個activity在新開進程里跑
- For example, if your application starts the activity in the camera application that captures a photo, that activity runs in the process that belongs to the camera application, not in your application's process. Therefore, unlike applications on most other systems, Android applications don't have a single entry point (there's no main() function, for example)
- Before the Android system can start an application component, the system must know that the component exists by reading the application's AndroidManifest.xml file (the "manifest" file). Your application must declare all its components in this file, which must be at the root of the application project directory.
You can start an activity (or give it something new to do) by passing an Intent to startActivity() or startActivityForResult() (when you want the activity to return a result).
You can start a service (or give new instructions to an ongoing service) by passing an Intent to startService(). Or you can bind to the service by passing an Intent to bindService().
You can initiate a broadcast by passing an Intent to methods like sendBroadcast(),sendOrderedBroadcast(), or sendStickyBroadcast().
You can perform a query to a content provider by calling query() on a ContentResolver.
Activities, services, and content providers that you include in your source but do not declare in the manifest are not visible to the system and, consequently, can never run. However, broadcast receivers can be either declared in the manifest or created dynamically in code (as BroadcastReceiver objects) and registered with the system by calling registerReceiver().
In order to receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter. The methods startActivity() and startActivityForResult() treat all intents as if they declared the CATEGORY_DEFAULT category. If you do not declare this category in your intent filter, no implicit intents will resolve to your activity.
onStop() is not guaranteed to be called, you can't always do in onStop() what is done in onPause().
Be aware that these semantics will change slightly between applications targeting platforms starting with HONEYCOMB vs. those targeting prior platforms. Starting with Honeycomb, an application is not in the killable state until its onStop() has returned. This impacts when onSaveInstanceState(Bundle) may be called (it may be safely called after onPause() and allows and application to safely wait until onStop() to save persistent state.
-
雖然Activity在功能上與UIViewController相似,但是生命周期的管理卻與Application相似(will/did已盡量區(qū)分):
- onCreate(bundle) -> willFinishLaunchingWithOptions(withOptions)
- onStart() -> applicationWillEnterForeground()
- onResume() -> applicationWillBecomeActive()
- onPause() -> applicationWillResignActive()
- onStop() -> applicationDidEnterForeground()
- onDestroy() -> applicationWillTerminate()
- onSaveInstanceState() -> AppDelegate::willEncodeRestorableStateWithCoder() / UIViewController::encodeRestorableStateWithCoder
- onRestoreInstanceState() -> AppDelegate::didDecodeRestorableState / UIViewController::decodeRestorableStateWithCoder
Because onSaveInstanceState() is not guaranteed to be called, you should use it only to record the transient state of the activity (the state of the UI)—you should never use it to store persistent data. Instead, you should use onPause() to store persistent data (such as data that should be saved to a database) when the user leaves the activity.
-
安卓A activity啟動B activity時callback順序是固定的(在B是本應(yīng)用同進程情況下), iOS應(yīng)該完全取決于transition的實現(xiàn):
- Activity A's onPause() method executes.
- Activity B's onCreate(), onStart(), and onResume() methods execute in sequence. (Activity B now has user focus.)
- Then, if Activity A is no longer visible on screen, its onStop() method executes.
安卓Paused和 iOSInactive最大區(qū)別是Inactive雖然不接受event,還能執(zhí)行代碼
onSaveInstanceState主要用來存儲臨時狀態(tài)如scroll position, 而onPause(pre HoneyComb)/onStop 用來存儲持久化數(shù)據(jù)~onSaveInstanceState在旋轉(zhuǎn)時尤為重要
Handler -> RunLoopContext(自定義), Looper -> RunLoop, 區(qū)別是安卓這邊做了更高層的封裝直接用Message傳遞信息給worker thread, 也就是說Message 完成了iOS的約定數(shù)據(jù)交互處職責和signal runloop職責(剛知道。。。安卓里worker thread不會睡)
@interface RunLoopContext : NSObject
{
CFRunLoopRef runLoop;
RunLoopSource* source;
}