目录搜索
androidManifestManifest.permissionManifest.permission_groupandroid.accessibilityserviceAccessibilityServiceandroid.accountsAccountandroid.appNotificationManagerandroid.bluetoothBluetoothAdapterBluetoothClassBluetoothClass.DeviceBluetoothClass.Device.MajorBluetoothClass.ServiceBluetoothDeviceBluetoothServerSocketBluetoothSocketandroid.contentSharedPreferencesandroid.database.sqliteSQLiteCursorDriverSQLiteOpenHelperandroid.graphicsBitmapandroid.locationLocationListenerGeocoderGpsStatusGpsStatus.ListenerGpsStatus.NmeaListenerGpsSatelliteandroid.mediaAudioFormatAsyncPlayerAudioRecordAudioRecord.OnRecordPositionUpdateListenerThumbnailUtilsAudioManagerandroid.netTrafficStatsMailToLocalSocketandroid.osAsyncTaskAsyncTask.StatusCountDownTimerMessageMessageQueueHandlerThreadandroid.textHtmlandroid.utilJsonWriterandroid.viewContextMenuContextMenu.ContextMenuInfoDisplayViewManagerViewViewStubViewTreeObserverViewParentWindowManagerGestureDetectorGravityMenuInflaterScaleGestureDetectorSoundEffectConstantsandroid.view.inputmethodInputConnectionInputMethodInputMethodSessionBaseInputConnectionInputMethodManagerandroid.widgetAbsListViewAbsListView.LayoutParamsAbsListView.OnScrollListenerAbsListView.RecyclerListenerAbsoluteLayoutAbsoluteLayout.LayoutParamsAbsSeekBarAbsSpinnerAdapterViewAdapterView.AdapterContextMenuInfoAdapterView.OnItemLongClickListenerAdapterView.OnItemSelectedListenerAdapterView.OnItemClickListenerAnalogClockBaseAdapterBaseExpandableListAdapterButtonCheckBoxCheckedTextViewCheckableChronometerChronometer.OnChronometerTickListenerCompoundButtonCompoundButton.OnCheckedChangeListenerCursorAdapterCursorTreeAdapterDatePickerDatePicker.OnDateChangedListenerDialerFilterDigitalClockEditTextFilterFilter.FilterListenerFilter.FilterResultsExpandableListAdapterExpandableListView.OnChildClickListenerExpandableListView.OnGroupClickListenerExpandableListView.OnGroupCollapseListenerExpandableListView.OnGroupExpandListenerFilterableGalleryGallery.LayoutParamsGridViewGridLayoutGridLayout.AlignmentRadioGroupImageViewImageView.ScaleTypeHorizontalScrollViewImageButtonImageSwitcherFilterQueryProviderListAdapterListViewMediaControllerMultiAutoCompleteTextViewMultiAutoCompleteTextView.CommaTokenizerMultiAutoCompleteTextView.TokenizerQuickContactBadgeRadioButtonRatingBarRatingBar.OnRatingBarChangeListenerRelativeLayoutRemoteViewsResourceCursorAdapterResourceCursorTreeAdapterScrollerScrollViewSearchViewSearchView.OnCloseListenerSearchView.OnQueryTextListenerSearchView.OnSuggestionListenerSeekBarSeekBar.OnSeekBarChangeListenerSimpleAdapterSimpleAdapter.ViewBinderSimpleCursorAdapterSimpleCursorAdapter.CursorToStringConverterSimpleCursorAdapter.ViewBinderSimpleCursorTreeAdapterSimpleCursorTreeAdapter.ViewBinderSimpleExpandableListAdapterSlidingDrawerSlidingDrawer.OnDrawerCloseListenerSlidingDrawer.OnDrawerOpenListenerSlidingDrawer.OnDrawerScrollListenerSpinnerSpinnerAdapterWrapperListAdapterTabHostTabHost.TabSpecTextViewTimePickerTimePicker.OnTimeChangedListenerToastTableLayoutTableLayout.LayoutParamsTableRowTableRow.LayoutParamsTabWidgetTextSwitcherToggleButtonTwoLineListItemVideoViewViewAnimatorViewFlipperViewSwitcherViewSwitcher.ViewFactoryZoomButtonsControllerZoomButtonsController.OnZoomListenerZoomButtonZoomControlsdalvik.systemDexFile
文字


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的关系


上一篇:下一篇: