前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >2016级移动应用开发在线测试11-线程

2016级移动应用开发在线测试11-线程

作者头像
达达前端
发布2022-04-29 08:07:02
6750
发布2022-04-29 08:07:02
举报
文章被收录于专栏:达达前端达达前端

1. 下面关于多线程技术描述错误的是()  

您的回答为:线程是进程的一个实体,是CPU调度和分派的基本单位。一个进程可以启动多个线程。线程不能够独立运行,总是属于某个进程,进程中的多个线程共享进程的内存。一个线程可以创建和撤销另一个线程;同一个进程中的多个线程之间可以并发执行。使用线程的优点在于线程创建、销毁和切换的负荷远大于进程。   

()线程是进程的一个实体,是CPU调度和分派的基本单位。一个进程可以启动多个线程。线程不能够独立运行,总是属于某个进程,进程中的多个线程共享进程的内存。一个线程可以创建和撤销另一个线程;同一个进程中的多个线程之间可以并发执行。使用线程的优点在于线程创建、销毁和切换的负荷远大于进程。

()现代操作系统是一个多任务的操作系统,即一次可以运行或提交多个作业,多线程技术正是实现多任务的基础,其意义在于一个应用程序中,有多个部分可以同时执行,从而可以获得更高的处理效率

()每个程序至少有一个进程,一个进程至少有一个线程。

()程序是一组指令的有序集合,本身没有任何运行的含义,只是一个静态的实体

()进程是在内存中运行的应用程序,反应了程序在一定的数据集上运行的全部动态过程,即一个程序如果没有被执行,就不会产生进程。每个进程都有自己独立的一块内存空间具有自己的生命周期。既进程通过创建而产生,通过系统调度而运行,当等待资源或事件时处于等待状态,在完成后被撤销

2. 以下对Android系统中的多线程描述错误的是()

您的回答为:ANR全称Application Not Responding,意思就是程序未响应,常见于两种情况:应用在15秒内未响应用户的输入事件(如按键或者触摸),BroadcastReceiver未在30秒内完成相关的处理   

()在多线程中,需要同步UI操作,必须借助于Handler或AsyncTask来完成异步处理

()当一个程序第一次启动时,Android会同时启动一个对应的主线程,主线程主要负责处理与UI相关的事件

()Android的主线程(UI线程是单线程的,Android的UI操作并不是线程安全的,UI操作必须在主线程中执行

()ANR全称Application Not Responding,意思就是程序未响应,常见于两种情况:应用在15秒内未响应用户的输入事件(如按键或者触摸),BroadcastReceiver未在30秒内完成相关的处理

()当需要在Android程序中运行比较耗时的操作时,如网络请求,大文件I/O等,为了不阻塞主线程(UI线程),需要使用多线程

3. 下面对Android系统消息和线程机制描述错误的是()

您的回答为:在一个Activity中无法创建多个组件或者子线程。   

()当应用程序启动时,Android会首先开启一个主线程,主线程负责进行事件分发。

()在一个Activity中无法创建多个组件或者子线程。 

()Activity是一个UI线程,运行于主线程中。

()如果Activity的线程或组件把自身的消息放入Activity的主线程消息队列,那么这些消息就回在主线程中被统一处理,而主线程一般负责界面的更新,因此这种方式可以较好地实现Android界面的更新。

()Android应用程序的消息处理机制是服务于线程的,每个线程都可以有自己的消息队列和消息循环的。

4. 以下对Handler类描述错误的是()  

您的回答为:Handler对象不属于创建它的线程。   

()从消息队列读取消息时会自动执行Handler中的handleMessage()方法,因此创建Handler时需要重写该方法,并在方法中编写实现消息逻辑处理的有关代码

()Handler的主要作用是接受子线程发送的数据,并利用这些数据来配合主线程更新UI。

()Handler包含了两个队列,其中一个是线程队列,另外一个是消息队列。

()Handler的post(Runnable)方法会将线程对象放到该Handler的线程队列中,sendMessage(Message message)方法可将消息放到消息队列中

()Handler对象不属于创建它的线程。

5. Message类用于定义发送给handler的消息,下面对于Message类描述错误的是()  

您的回答为:Message对象只能包含java的原生数据类型   

()Message对象只能包含java的原生数据类型

()message类有一些设置属性的方法,例如:setTarget()设置处理的Handler对象,setData(Bundle bundle)设置消息的数据

()Message对象可以通过直接使用无参数的构造函数来生成,但更好的方法是调用message.obtain()方法或者HandlerobtainMessage()方法,这样可以从可回收对象池中获取Message对象。

()Message类有一些获取属性的方法,例如:getData()获得消息的数据,getTarget()获得处理该消息的Handler对象,

6. Message类有几个public类型的字段,可以用于设置Message携带的信息,下面描述正确的是()

http://android.xsoftlab.net/reference/android/os/Message.html

您的回答为:

public int arg1,public int arg2:如果是只需要存储整型数据,建议直接对arg1,arg2进行赋值,而不是调用setData()方法。┋

public Object obj:发送给接收器的对象类型的信息┋

public Messager replyTo:指明响应此message的Messenger对象┋

public int what:用户自定义的消息代码,可以理解位消息的ID。每个Handler对消息代码有自己的命名空间,所以不用担心自定义的消息跟其他Handler发生冲突。┋

public int sendingUid:标示发送这个消息的对象的uid,只有在发送者是Messenger时才会有值,其他情况值为-1   

全选

7. AysncTask是Android提供的轻量级异步任务类,能够较容易地实现UI线程的更新。下面关于AsyncTask类描述错误的是()

http://android.xsoftlab.net/reference/android/os/AsyncTask.html

您的回答为:

可以手动调用onPreExecute(),onPostExecute(Result),doInBackground(Params...),onProgressUpdate(Progress...)这四个方法   

()AysncTask的异步任务在后台线程中运行,AsyncTask提供的接口既可以传递当前异步执行的进度信息,实现UI界面的更新,又能够在最后将执行的结果反馈给UI主线程

()可以手动调用onPreExecute(), onPostExecute(Result), dolnBackground(Params...), onProgressUpdate(Progress...)这四个方法

()使用AsyncTask进行多线程编程时,需要继承AsyncTask类,必须重写dolnBackground方法,该方法是后台执行方法,比较耗时的操作都要放在这里,任务的执行结果由这个方法返回。在执行过程中可以通过publicProgress方法来更新任务的进度。

()一个AsyncTask是由3个泛型类型Params, Progress和Result的参数和4个方法PreExecute, dolnBackground, onProgressUpdate及onPostExecute构成。其中Params参数表示启动执行是需要输入的参数;Progress表示后台任务执行期间需要反馈回UI界面的数据;Result表示后台执行任务完毕后返回的结果。

()AsyncTask类的实例必须在UI线程中创建,即在主线程中创建;execute(Params...)方法必须在UI线程中调用;AyncTask方法只能被执行一次,若多次调用将会抛出异常

8. AsyncTask is a very important class in android.os package, it's features are?

http://android.xsoftlab.net/reference/android/os/AsyncTask.html

您的回答为:

AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.┋

AsyncTask is designed to be a helper class around Thread and Handler and does not constitute a generic threading framework.┋

AsyncTasks should ideally be used for short operations (a few seconds at the most.) If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent package such as Executor, ThreadPoolExecutor and FutureTask.┋

An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by 3 generic types, called Params, Progress and Result, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and onPostExecute.┋

AsyncTask must be subclassed to be used. The subclass will override at least one method (doInBackground(Params...)), and most often will override a second one (onPostExecute(Result).)  

全选

9. There are a few threading rules that must be followed for AsyncTask class to work properly, which one is not true ?  

您的回答为:The AsyncTask class must be loaded on the UI thread. This is done automatically as of OREO.   

()execute(Params...) must be invoked on the UI thread.

()Do not call onPreExecute(), on PostExecute(Result), dolnBackground(Params...), onProgressUpdate(Progress...) manually.

()The task instance must be created on the UI thread.

()The AsyncTask class must be loaded on the UI thread. This is done automatically as of OREO.

()The task can be executed only once (an exception will be thrown if a second execution is atte mpted.)

10. In Android Message system, Handler makes very low-level effect, it can be?

http://android.xsoftlab.net/reference/android/os/AsyncTask.html

您的回答为:Each Handler instance is associated with a many threads and that threads' message queues.   

()When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messges and runnables to that message queue and execute them as they come out of the message queue.

()Each Handler instance is associated with a many threads and that thread's message queues.

()When posting  or sending to a Handler, you can either allow the item to be processed as soon as the message queue is ready to do so, or specify a delay before it gets processed or absolute time for it to be processed. The latter two allow you to implement timeouts, ticks, and otheer timing-based behavior.

()Scheduling messages is accomplished with the post(Runnable), postAtTime(Runnable, long), postDelayed(Runnable, long), sendEmptyMessage(int), sendMessage(Message), sendMessageAtTime(Message, long), and sendMessageDelayed(Message, long) methods.

()When a process is created for your application, its main thread is dedicated to running a mess age queue that takes care of managing the top-level application objects(activities, broadcast receivers, etc) and any windows they create.

()There are two main uses for a Handler: (1) to schedule messages and runnables to be executed as some point in the future; and (2) to enqueue an action to be performed on a different thread than your own.

()A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue.

()The post versions allow you to enqueue Rennable objects to be called by the message queue when they are received; the sendMessage versions allow you to enqueue a Message object containing a bundle of data that will be processed by the Handler's handleMessage(Message) method (requiring that you implement a subclass of Handler).

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-01-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档