WEB开发网
开发学院手机开发Android 开发 Android 开发基础 Threads 阅读

Android 开发基础 Threads

 2010-07-15 21:19:00 来源:WEB开发网   
核心提示:即使你可以限制您的程序在一个单独的进程里,但总有需要产生一个线程来做一些后台工作的时候,Android 开发基础 Threads,由于用户界面必须及时相应用户的操作,含有一个activity的线程最好不要同时含有一个资源占用比较大运算,android提供了一些方便的类来管理线程:在一个线程中运行消息循环的Looper,

即使你可以限制您的程序在一个单独的进程里,但总有需要产生一个线程来做一些后台工作的时候。由于用户界面必须及时相应用户的操作,含有一个activity的线程最好不要同时含有一个资源占用比较大运算,比如下载。任何不会很快结束的运算都应该放在不同的线程里。

线程是用标准java线程对象在代码中创建的。android提供了一些方便的类来管理线程:在一个线程中运行消息循环的Looper,处理消息的Handler,建立一个带有loop循环的线程的HandlerThread。

原文

Threads

Even though you may confine your application to a single process, there will likely be times when you will need to spawn a thread to do some background work. Since the user interface must always be quick to respond to user actions, the thread that hosts an activity should not also host time-consuming operations like network downloads. Anything that may not be completed quickly should be assigned to a different thread.

Threads are created in code using standard Java Thread objects. Android provides a number of convenience classes for managing threads — Looper for running a message loop within a thread, Handler for processing messages, and HandlerThread for setting up a thread with a message loop.

Tags:Android 开发 基础

编辑录入:coldstar [复制链接] [打 印]
赞助商链接