`

android培训文档提纲(二)

阅读更多
一、Each Activity can make an Intent call to get something done without knowing exactly who’ll receive that Intent
Android的这种调用方式,是一种各组件之间低耦合的集成方式。比如自己的应用需要调用打电话的功能,可以创建一个Intent.setAction(DIAL),请求“某一个”电话程序来完成打电话功能。如果没有安装第三方的程序,那么通常手机自带的电话程序会响应这个请求,如果安装了第三方的拨号程序(当然这种情况很少),那么就会由第三方拨号程序完成通话。而原来的Activity,对这一切是一无所知的

二、用intent来描述意图,然后用intent-filter来进行全局匹配。如果找到唯一结果,就进行调用;如果找到多个结果,则要求用户选择;如果没有找到结果,则抛出异常。手机上安装的所有程序,无论是自带的,还是第三方应用,都会参与这个匹配过程。当然,如果在manifest.xml中没有设置intent-filter,就不会参与到intent匹配。这种情况下,这种组件就只能通过显式调用被调用到

三、
Action:     Fully qualified String indicating the action (for example, android.intent.action.DIAL)
Category:   Describes where and how the Intent can be used, such as from the main
            Android menu or from the browser
Component:  Specifies an explicit package and class to use for the Intent, instead of inferring from action, type, and categories
Data:       Data to work with, expressed as a URI (for example, content://contacts/1)
Extras:     Extra data to pass to the Intent in the form of a Bundle
Type:       Specifies an explicit MIME type, such as text/plain or vnd.android.cursor.item/email_v2

四、implicit and explicit invocation。这个说的是隐式调用和显式调用

五、Android parses each <intent-filter> element into an IntentFilter object. After Android installs an .apk file, it registers the application’s components, including the Intent filters. When the platform has a registry of Intent filters, it can map any Intent requests to the correct, installed Activity, BroadcastReceiver, or Service

六、下面是intent-filter的匹配规则

Action: Each individual IntentFilter can specify zero or more actions and zero or more categories. If the action isn’t specified in the IntentFilter, it’ll match any Intent; otherwise, it’ll match only if the Intent has the same action

Category: An IntentFilter with no categories will match only an Intent with no categories; otherwise, an IntentFilter must have at least what the Intent specifies. For example,if an IntentFilter supports both the HOME and the ALTERNATIVE categories, it’ll match an Intent for either HOME or CATEGORY. But if the IntentFilter doesn’t provide any categories, it won’t match HOME or CATEGORY

Data: scheme://authority/path分别对应android:schema、android:host、android:path

七、A broadcast Intent doesn’t invoke an Activity, so your current screen usually remains in the foreground

八、Android best practices discourage long-running services. Services that run continually and constantly use the network or perform CPU-intensive tasks will eat up the device’s battery life and might slow down other operations

九、In Android, each application runs within its own process. Other applications can’t directly call methods on some service of another application, because the applications are in different sandboxes

十、If you want to allow other developers to use your weather features, you need to give them information about the methods you provide, but you might not want to share your application’s source code. Android lets you specify your IPC features by using an interface definition language (IDL) to create AIDL files

十一、Service lifecycle

SERVICE-STARTED LIFECYCLE: If you start a Service by calling Context.startService(), it runs in the background whether or not anything binds to it. If the service hasn’t been created, the Service onCreate() method is called. The onStart() method is called each time someone tries to start the service, whether or not it’s already running. Additional instances of the Service won’t be created. The Service will continue to run in the background until someone explicitly stops it with the Context.stopService() method or when the Service calls its own stopSelf() method. You should also keep in mind that the platform might kill services if resources are running low, so your application needs to be able to react accordingly

SERVICE-BOUND LIFECYCLE: If an Activity binds a Service by calling Context.bindService(), it’ll run as long
as the connection is open. An Activity establishes the connection using the Context and is also responsible for closing it. When a Service is only bound in this manner and not also started, its onCreate() method is invoked, but onStart() is not used. In these cases, the platform can stop and clean up the Service after it’s unbound

CLEANING UP WHEN A SERVICE STOPS: When a Service stops, its onDestroy() method is invoked. Inside onDestroy(), every Service should perform final cleanup, stopping any spawned threads, terminating network connections, stopping services it had started, and so on
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics