移动互联网课考的是安卓。。。作为iOS程序员建立了一下对应关系。。。不知道能不能过=。=
- 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 共享数据,不像iOS只能copy一份
- Broadcast Receiver 与 iOS 中的NSNotificationCenter略有不同 还能唤醒App真是666,终于知道百度全家桶的由来
- 安卓中activity有返回值吗?(用别的App拍照返回照片)
- 有的,通过Intent传回
- 优点:低耦合
- 缺点:类型不安全,其实还是存在耦合(需要提前知道类型)
- 安卓用其它应用的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已尽量区分):
- 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是本应用同进程情况下), iOS应该完全取决于transition的实现:
- 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最大区别是Inactive虽然不接受event,还能执行代码
onSaveInstanceState主要用来存储临时状态如scroll position, 而onPause(pre HoneyComb)/onStop 用来存储持久化数据~onSaveInstanceState在旋转时尤为重要
Handler -> RunLoopContext(自定义), Looper -> RunLoop, 区别是安卓这边做了更高层的封装直接用Message传递信息给worker thread, 也就是说Message 完成了iOS的约定数据交互处职责和signal runloop职责(刚知道。。。安卓里worker thread不会睡)
@interface RunLoopContext : NSObject
{
CFRunLoopRef runLoop;
RunLoopSource* source;
}