目录 搜索
android Manifest Manifest.permission Manifest.permission_group android.accessibilityservice AccessibilityService android.accounts Account android.app NotificationManager android.bluetooth BluetoothAdapter BluetoothClass BluetoothClass.Device BluetoothClass.Device.Major BluetoothClass.Service BluetoothDevice BluetoothServerSocket BluetoothSocket android.content SharedPreferences android.database.sqlite SQLiteCursorDriver SQLiteOpenHelper android.graphics Bitmap android.location LocationListener Geocoder GpsStatus GpsStatus.Listener GpsStatus.NmeaListener GpsSatellite android.media AudioFormat AsyncPlayer AudioRecord AudioRecord.OnRecordPositionUpdateListener ThumbnailUtils AudioManager android.net TrafficStats MailTo LocalSocket android.os AsyncTask AsyncTask.Status CountDownTimer Message MessageQueue HandlerThread android.text Html android.util JsonWriter android.view ContextMenu ContextMenu.ContextMenuInfo Display ViewManager View ViewStub ViewTreeObserver ViewParent WindowManager GestureDetector Gravity MenuInflater ScaleGestureDetector SoundEffectConstants android.view.inputmethod InputConnection InputMethod InputMethodSession BaseInputConnection InputMethodManager android.widget AbsListView AbsListView.LayoutParams AbsListView.OnScrollListener AbsListView.RecyclerListener AbsoluteLayout AbsoluteLayout.LayoutParams AbsSeekBar AbsSpinner AdapterView AdapterView.AdapterContextMenuInfo AdapterView.OnItemLongClickListener AdapterView.OnItemSelectedListener AdapterView.OnItemClickListener AnalogClock BaseAdapter BaseExpandableListAdapter Button CheckBox CheckedTextView Checkable Chronometer Chronometer.OnChronometerTickListener CompoundButton CompoundButton.OnCheckedChangeListener CursorAdapter CursorTreeAdapter DatePicker DatePicker.OnDateChangedListener DialerFilter DigitalClock EditText Filter Filter.FilterListener Filter.FilterResults ExpandableListAdapter ExpandableListView.OnChildClickListener ExpandableListView.OnGroupClickListener ExpandableListView.OnGroupCollapseListener ExpandableListView.OnGroupExpandListener Filterable Gallery Gallery.LayoutParams GridView GridLayout GridLayout.Alignment RadioGroup ImageView ImageView.ScaleType HorizontalScrollView ImageButton ImageSwitcher FilterQueryProvider ListAdapter ListView MediaController MultiAutoCompleteTextView MultiAutoCompleteTextView.CommaTokenizer MultiAutoCompleteTextView.Tokenizer QuickContactBadge RadioButton RatingBar RatingBar.OnRatingBarChangeListener RelativeLayout RemoteViews ResourceCursorAdapter ResourceCursorTreeAdapter Scroller ScrollView SearchView SearchView.OnCloseListener SearchView.OnQueryTextListener SearchView.OnSuggestionListener SeekBar SeekBar.OnSeekBarChangeListener SimpleAdapter SimpleAdapter.ViewBinder SimpleCursorAdapter SimpleCursorAdapter.CursorToStringConverter SimpleCursorAdapter.ViewBinder SimpleCursorTreeAdapter SimpleCursorTreeAdapter.ViewBinder SimpleExpandableListAdapter SlidingDrawer SlidingDrawer.OnDrawerCloseListener SlidingDrawer.OnDrawerOpenListener SlidingDrawer.OnDrawerScrollListener Spinner SpinnerAdapter WrapperListAdapter TabHost TabHost.TabSpec TextView TimePicker TimePicker.OnTimeChangedListener Toast TableLayout TableLayout.LayoutParams TableRow TableRow.LayoutParams TabWidget TextSwitcher ToggleButton TwoLineListItem VideoView ViewAnimator ViewFlipper ViewSwitcher ViewSwitcher.ViewFactory ZoomButtonsController ZoomButtonsController.OnZoomListener ZoomButton ZoomControls dalvik.system DexFile
文字


HandlerThread

版本:Android 3.1 r1

 

结构

继承关系

public class HandleThread extends Thread

        

java.lang.Object

java.lang.Thread

        android.os.HandlerThread

 

类概述

用于方便的创建一个含有looper的线程类。looper用来创建handler类。请注意,仍然需要调用start()方法。

 

构造函数

public HandlerThread (String name)

构造一个HandlerThread

 

public HandlerThread (String name, int priority)

构造一个HandlerThread

参数

priority  运行线程的优先级,这个值是由Android.os.Process提供而不是来自java.lang.Thread.

 

公共方法

public Looper getLooper ()

这个方法返回与此线程相关的Looper。如果该线程不能启动或是由于某种原因isAlive()方法返回false,则这个方法返回null,假如这个线程已经启动,那么此方法将阻塞,直到looper被初始化。

返回值

Looper

 

public int getThreadId ()

返回线程的标志。详见:Process.myTid()

 

public boolean quit ()

查看当前运行的looper是否已经退出。假如线程这未启动或者已经结束(即getLooper()方法返回null),这个方法将返回false。否则looper被要求退出并返回true

 

public void run ()

调用设置Runnable对象的run()方法。如果没有设置Runnable,什么也不做。

 

受保护方法

protected void onLooperPrepared ()

如果需要在Looper循环之前执行一些设置,可明确继承该回调方法。

(译者注:如下代码:

         void run() {

                   mTid = Process.myTid();

                   Looper.prepare();//创建一个Looper实例,并且存储在ThreadLocal中,ThreadLocal中维护一个HashMap,键是线程号

                  synchronized (this) {

                            mLooper = Looper.myLooper();//得到当前线程的Looper,就是刚才perpare方法中创建并存储的那个Looper实例

                            Process.setThreadPriority(mPriority);

                            notifyAll();

                   }

         onLooperPrepared();

         Looper.loop();//开始轮询

         mTid = -1;

 

补充

文章精选

             Android开发入门——handler使用(二)

             AsyncQueryHandler研究

                   ThreadLooper以及HandlerMessage详解 Android开发必读 [Android123]

                   android Thread HandlerThread Looper Message MessageQueue Handler的关系


上一篇: 下一篇: