2016级移动应用开发在线测试12-service

有趣有内涵的文章第一时间送达!


 喝酒I创作I分享


生活中总有些东西值得分享

@醉翁猫咪 

Service是Android系统中的四大组件之一(Acitivty、Service、ContentProvider、BroadcastReceiver),以下关于Service描述错误的是()  


您的回答为:在Android中能开机自启动的那些才是Service,无法开机自启动的就不是Service。 


()Service与Activity类似,它的运行也有生命周期,都是Context的子类,但它没有用户界面而且只能在后台运行。即使用户换到其他的应用程序,Service还可以继续在后台运行。


()Service还可以用于进程间通信(Inter Process Communication IPC),解决两个不同Activity应用程序进程之间的调用和通信。首先用AIDL语言定义跨进程服务的接口,然后继承Service类实现跨进程服务,绑定和使用跨进程服务,就可以将数据打包进行进程间通讯了


()在Android中能开机自启动的那些才是Service,无法开机自启动的就不是Service。


()Service比Activity有个更高的优先级(在系统中永远运行的组件)。在系统资源紧张时,Service不会轻易被Android系统终止。在系统资源恢复后,Service也将自动恢复运行状态


()Service的启动/停止,绑定/解绑都是使用Intent来进行调用和消息传递的。


下面哪一种不是android服务的类型  


您的回答为:手动服务(manual service)   


()绑定服务(bound service)


()本地服务(local service)


()信使服务(intent service)


()手动服务(manual service)


()远程服务(remote service)


()启动服务(started service)


()前台服务(foreground service)


Service的启动方式一般常用Started服务(启动服务)和Bound服务(绑定服务)两种,下面关于这两种启动服务方式的对比错误的是()


您的回答为:使用bindService()方法无法绑定由startService()方法启动的服务。startService()方法无法启动bindService()方法绑定的服务   


()无论调用了多少次StartService(),只需要调用一次stopService()就可以停止Started服务。只有当所有的组件都调用unbindService()来解除与Bound服务的绑定后,Bound服务才会销毁


()Started服务是指组件通过调用startService()来启动服务。Bound服务是组将通过bindService()来绑定服务


()一般来说Started服务执行单一的操作,不返回结果给调用组件。Bound服务允许组件与服务进行交互,例如向服务发送请求和获取结果


()即使调用Started服务的组件被销毁,该Started服务依然可以继续运行。当没有组件和Bound服务绑定时,该Bound服务将会被销毁。


()使用bindService()方法无法绑定由startService()方法启动的服务。startService()方法无法启动bindService()方法绑定的服务


要创建一个服务,需要定义Service子类继承于Service,并且重写一些重要的回调方法用于处理服务的生命周期,以下关于Service类方法的描述错误的是() 


您的回答为:onUnbind():当一个组件想通过bindService()方法绑定服务时,该方法将会被系统调用。   


()onUnbind():当一个组件想通过bindService()方法绑定服务时,该方法将会被系统调用。


()onCreate():当服务第一次被创建时,该方法将会被系统调用。该方法在onStartCommand()或onBind()方法之前调用


()onBind():这是一个必须实现的方法。当一个组件想通过bindService()方法绑定服务时,该方法将会被系统调用。该方法通过返回IBinder来提供组件与服务的通信接口。如果用户不允许绑定,那么只需要返回null


()onStartCommand():当组件通过StartService()方法请求服务启动时,该方法将被系统调用。在该方法内,会接收到组件传过来的Intent,里面包含有关服务的数据。一旦该方法开始执行,服务就能够在后台运行。对于Bound服务,不需要实现该方法。


()onDestory():当服务不再使用或这在被销毁时,该方法将被系统调用。在个方法中,实现对线程,监听器等资源的清理或者释放。


下面对于android服务叙述错误的是。


https://www.cnblogs.com/leslies2/p/5401813.html
 

您的回答为:Service 服务不会自动创建线程,如果开发人员没有为Service服务添加异步操作,那Service服务将运行于主线程当中。服务主线程运行时间过长也会产生ANR,服务主线程ANR的超时时间是60秒。   


()本地服务(Local Service)寄存于当前的进程当中,当前进程结束后Service也会随之结束,Service可以随时与Activity等多个部件进行信息交换。Service服务不会自动启动线程,如果没有人工调用多线程方式进行启动,Service将寄存于主线程当中。


()Service服务主要分为Local Service本地服务与Remote Service远程服务两种,本地服务只支持同一进程内的应用程序进行访问,远程服务可通过AIDL(Android Interface Definition Language)技术支持跨进程访问。


()Service服务不会自动创建线程,如果开发人员没有为Service服务添加异步操作,那Service服务将运行于主线程运行时间过长也会产生ANR,服务主线程ANR的超时时间是60秒。


()服务可以通过Context.startService()和Context.bindService()进行启动,一般Local Service本地服务可使用其中一种方法启动,但Remote Service远程服务只能使用Context.bindService()启动,而两种调用方式在使用场景与活动流程中都存在差异。


()Service服务是Android系统最常用的四大部件之一,Android支持Service服务的原因主要目的有两个,一是简化后台任务的实现,二是实现在同一台设备当中跨进程的远程信息通信。


()远程服务(Remote Service)独立寄存于另一进程中,通过AIDL(Android Interface Definition Language)接口 定义语言,实现Android设备上的两个进程间通信(IPC)。AIDL的IPC机制是基于RPC(Remote Proceduce Call)远程过程调用协议建立的,用于约束两个进程间的通讯规则,供编译器生成代码。进程之间的通信信息,首先会被转换AIDL协议消息,然后发送给对方,对方收到AIDL协议消息后再转换成相应的对象。


Bound Service 是允许其他的组件(如 Activities)绑定到其上面,可以发送请求,也可以接受请求,甚至可以进行进程间的通信。当创建一个能提供绑定功能的服务时,我们就必须要提供一个IBinder对象,客户端就可以使用IBinder对象来与服务进行交互,在Android系统中,以下哪种方式可以创建IBinder  


您的回答为:


扩展Binder类:这种方式当你的service只给当前的程序用而且在后台执行的时候采用这种方式比较好。意思很简单,不需要跨进程间通信。┋


使用Message机制:消息机制相对于Binder的方式就比较复杂点,它支持跨进程间调用的(这种方式的基础其实也是AIDL,只不过不需要涉及到AIDL那么深),这种情况下,service会定义一个handle来处理不同的object的服务请求,有一点要提起的是,这里的IBinder对所有的客户端来说是共享的。


当然我们的客户端也可以定义自己的handle来处理和service之间来进行交互。消息机制是一种实现进程间通信的最简单的方式,因为所有的请求都会放到一个消息队列当中去进行轮询处理(意思就是单线程啦),每次只处理一个服务请求,这样就不要保证你设计的service需要保证是线程安全状态的。┋


使用AIDL(Android interface definition language 安卓接口定义语言)。:这种方式是最难的一种方式了,他会把所有的工作都会分解成最原始的语义,从而使得系统能够理解该工作目的。然后进行进程间的通信。


前面说过message采用的是AIDL的架构基础的,当我们需要同时处理多个请求,而不是放在队列里面一个一个的处理的时候就可以采用这种方式了。使用这种方式你必须保证的你的service能够支持多线程并且保证其实线程安全状态。一般情况下会先创建一个.aldl文件来定义程序的接口,系统会为你自动自动生成抽象类以及IPC的处理,然后你就可以在你的service种进行extend了。   


全选


以下对intentservice描述错误的是  


您的回答为:intentservice本质是一种特殊的Service,继承自Service是一个最终类。   


()intentservice可以用于在后台执行耗时的异步任务,当任务完成后会自动停止


()intentservice拥有较高的优先级,不易被系统杀死(继承自Service的缘故),因此比较适合执行一些高优先级的异步任务


()即使我们多次启动IntentService,但IntentService的实例只有一个,这跟传统的Service是一样的,最终IntentService会去调用onHandleIntent执行异步任务。


()intentservice本质是一种特殊的Service,继承自Service是一个最终类。


()创建IntentService时,只需实现onHandleIntent和构造方法,onHandleIntent为异步方法,可以执行耗时操作。


()intentservice内部通过HandlerThread和Handler实现异步操作


()继承IntentService,有两个方法必须实现,一个是构造方法,必须传递一个线程名称的字符串,另外一个就是进行异步处理的方法onHandleIntent(Intent intent)方法,其参数intent可以附带从activity传递过来的数据。


which one is wrong about android service. 


http://android.xsoftlab.net/reference/android/app/Service.html

您的回答为:A Service is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map.   


()Note that services, like other application objects, run in the main thread of their hosting process. This means that, if your service is goig to do any CPU intensive (such as MP3 playback) or blocking (such as networking) operations, it should spawn its own thread in which to da that work.


()Each service class must have a corresponding <service> declaration in its package's Android Manifest.xml.


()A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.


()A Service is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, send an email, or view a map. 


()Services can be started with Context.startService() and Context.bindService()


()The IntentService class is available as a standard implementation of Service that has its own thread where it schedules its work to be done.


Which callback methods you should not override when create subaclss of Service. 


http://android.xsoftlab.net/guide/components/services.html   


您的回答为:startService():Request that a given application service be started.   


()startService():Request that a given application service be started.


()onStartCommand():The system calls this method when another component, such as an activity, requests that the service be started, by calling startService(). Once this method executes, the service is started and can run in the background indefinitely. If you implement this, it is your responsibility to stop the service when its work is done, by calling stopSelf() or stopService().(If you only want to provide binding, you don't need to implement this method.)


()onBind():The system calls this method when another component wants to bind with the service (such as to perform RPC), by calling bindService(). In your implementation of this method, you must provide an interface that clients use to communicate with the service, by returning an IBinder. You must always implement this method, but if you don't want to allow binding, then you should return null.


()onCreate(): The system calls this method when the service is first created, to first created, to perform one-time setup procedures (before it calls either onStartCommand() or onBind()).If the service is already running, this method is not called.


()onDestroy(): The system calls this method when the service is no longer used and is being destroyed. Your service should implement this to clean up any resources such as threads, registered listeners, receivers, etc. This is the last call the service receives.


Which type of job that IntentService can not do with?


http://android.xsoftlab.net/guide/components/services.html  


您的回答为:Manage access to a structured set of data, encapsulate the data, and provide mechanisms for defining data security.   


()Provides a default implementation of onStartCommand() that sends the intent to the work queue and then to your onHandleIntent() implementation.


()Creates a default worker thread that executes all intents delivered to onStartCommand() separate from your application's main thread.


()Manage access to a structured set of data, encapsulate the data, and provide mechanisms for defining data security.


()Provides default implementation of onBind() that returns null.


()Creates a work queue that passes one intent at a time to your onHandleIntent() implementation, so you never have to worry about multi-threading.


()Stops the service after all start requests have been handled, so you never have to call stopSelf().


后续

关注我,每天都有优质技术文章推送。工作,学习累了的时候放松一下自己。

本篇文章同步微信公众号

欢迎大家关注我的微信公众号:「醉翁猫咪」


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值