Example usage for android.os HandlerThread start

List of usage examples for android.os HandlerThread start

Introduction

In this page you can find the example usage for android.os HandlerThread start.

Prototype

public synchronized void start() 

Source Link

Document

Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

Usage

From source file:cn.yibulz.caviewtest.MainActivity.java

private Handler getBackgroundHandler() {
    if (mBackgroundHandler == null) {
        HandlerThread thread = new HandlerThread("background");
        thread.start();
        mBackgroundHandler = new Handler(thread.getLooper());
    }//from ww  w . jav a 2  s . c om
    return mBackgroundHandler;
}

From source file:com.grass.caishi.cc.service.BaseIntentService.java

/**
 * Creates an IntentService. Invoked by your subclass's constructor.
 * //from   w  w  w.j  a  v  a 2s  .  c om
 * @param name
 *            Used to name the worker thread, important only for debugging.
 */
// public BaseIntentService(Context context){
// super(context);
// }

// public class BroadCastListen extends BroadcastReceiver{
// @Override
// public void onReceive(Context context, Intent intent) {
// // TODO Auto-generated method stub
// int ddo=intent.getIntExtra("do", 0);
// int fileid=intent.getIntExtra("imageId", 0);
// String str=intent.getAction();
// if(str.equals(broadcase)&&ddo==UP_DEL&&fileid!=0){
// mServiceHandler.removeMessages(fileid);
// for (int i = 0; i < filelist.size(); i++) {
// ImageItem fu=filelist.get(i);
// if(fu.imageId==fileid){
// filelist.remove(i);
// intent.putExtra("do", UP_DEL);
// sendBroadcast(intent);
// break;
// }
// }
// }
// }
// }

@Override
public void onCreate() {
    super.onCreate();
    // filelist.clear();
    intent = new Intent(BroadCastName);
    // broadcase=new BroadCastListen();
    // IntentFilter filter=new IntentFilter(BroadCastName);
    // registerReceiver(broadcase, filter);

    HandlerThread thread = new HandlerThread("IntentService[" + mName + "]");
    thread.start();

    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);
}

From source file:org.anhonesteffort.flock.ContactCopyService.java

@Override
public void onCreate() {
    HandlerThread thread = new HandlerThread("ContactCopyService", HandlerThread.NORM_PRIORITY);
    thread.start();

    serviceLooper = thread.getLooper();//from w ww  .j av  a  2s .co  m
    serviceHandler = new ServiceHandler(serviceLooper);

    notifyManager = (NotificationManager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(getBaseContext());
    accountErrors = new LinkedList<Bundle>();
}

From source file:com.lithiumli.fiction.NowPlayingActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.now_playing);
    initializeDrawer(false);/*from  w ww .j ava  2  s  .c o  m*/

    mCoverPager = (AlbumSwiper) findViewById(R.id.cover_pager);
    mCoverPager.setListener(this);

    mSongName = (TextView) findViewById(R.id.np_song_name);
    mSongAlbum = (TextView) findViewById(R.id.np_song_album);
    mSongArtist = (TextView) findViewById(R.id.np_song_artist);
    mSongArtist.setSelected(true);

    ActionBar ab = getActionBar();
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setTitle("Now Playing");

    mCache = ArtistImageCache.getInstance(this);

    setQueueMargin();

    HandlerThread thread = new HandlerThread("thread");
    thread.start();

    mLooper = thread.getLooper();
    mHandler = new Handler(mLooper);

    mFadeOut = new FadeOut();
    mHandler.postDelayed(mFadeOut, 2000);
}

From source file:MainActivity.java

protected void takePicture(View view) {
    if (null == mCameraDevice) {
        return;// w  ww. ja v  a  2  s.  co m
    }
    CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
    try {
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraDevice.getId());
        StreamConfigurationMap configurationMap = characteristics
                .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        if (configurationMap == null)
            return;
        Size largest = Collections.max(Arrays.asList(configurationMap.getOutputSizes(ImageFormat.JPEG)),
                new CompareSizesByArea());
        ImageReader reader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG,
                1);
        List<Surface> outputSurfaces = new ArrayList<Surface>(2);
        outputSurfaces.add(reader.getSurface());
        outputSurfaces.add(new Surface(mTextureView.getSurfaceTexture()));
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(reader.getSurface());
        captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
        ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
            @Override
            public void onImageAvailable(ImageReader reader) {
                Image image = null;
                try {
                    image = reader.acquireLatestImage();
                    ByteBuffer buffer = image.getPlanes()[0].getBuffer();
                    byte[] bytes = new byte[buffer.capacity()];
                    buffer.get(bytes);
                    OutputStream output = new FileOutputStream(getPictureFile());
                    output.write(bytes);
                    output.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if (image != null) {
                        image.close();
                    }
                }
            }
        };
        HandlerThread thread = new HandlerThread("CameraPicture");
        thread.start();
        final Handler backgroudHandler = new Handler(thread.getLooper());
        reader.setOnImageAvailableListener(readerListener, backgroudHandler);
        final CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() {
            @Override
            public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
                    TotalCaptureResult result) {
                super.onCaptureCompleted(session, request, result);
                Toast.makeText(MainActivity.this, "Picture Saved", Toast.LENGTH_SHORT).show();
                startPreview(session);
            }
        };
        mCameraDevice.createCaptureSession(outputSurfaces, new CameraCaptureSession.StateCallback() {
            @Override
            public void onConfigured(CameraCaptureSession session) {
                try {
                    session.capture(captureBuilder.build(), captureCallback, backgroudHandler);
                } catch (CameraAccessException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onConfigureFailed(CameraCaptureSession session) {
            }
        }, backgroudHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.google.android.gms.location.sample.locationupdatesforegroundservice.LocationUpdatesService.java

@Override
public void onCreate() {
    mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
    mGoogleApiClient.connect();/* ww  w  .java2s. co  m*/
    createLocationRequest();

    HandlerThread handlerThread = new HandlerThread(TAG);
    handlerThread.start();
    mServiceHandler = new Handler(handlerThread.getLooper());
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}

From source file:com.nolanlawson.cordova.sqlite.SQLitePlugin.java

private Handler createBackgroundHandler() {
    HandlerThread thread = new HandlerThread("SQLitePlugin BG Thread");
    thread.start();
    return new Handler(thread.getLooper());
}

From source file:com.cssweb.android.quote.DaPan.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    HandlerThread mHandlerThread = new HandlerThread("CSSWEB_THREAD");
    mHandlerThread.start();
    mHandler = new MessageHandler(mHandlerThread.getLooper());

    this.activityKind = Global.QUOTE_DAPAN;

    setContentView(R.layout.zr_table);/*from  w w  w .  j a v  a 2  s .c o  m*/

    String[] toolbarname = new String[] { Global.TOOLBAR_MENU, Global.TOOLBAR_SHANGYE, Global.TOOLBAR_XIAYIYE,
            Global.TOOLBAR_REFRESH };

    initTitle(R.drawable.njzq_title_left_back, 0, "");
    initToolBar(toolbarname, Global.BAR_TAG);

    cols = getResources().getStringArray(R.array.index_cols);

    //????
    pageNum = CssSystem.getTablePageSize(mContext);
    rowHeight = CssSystem.getTableRowHeight(mContext);

    begin = 1;
    end = pageNum;
    allStockNums = StockInfo.getStockInfoSize(20);
    setToolBar(1, false, R.color.zr_newlightgray);
    init(2);
}

From source file:org.teleportr.ConnectorService.java

@Override
public void onCreate() {
    HandlerThread thread = new HandlerThread(WORKER);
    thread.start();
    worker = new Handler(thread.getLooper());
    reporter = new Handler();
    try {/*w w w.ja  va 2 s  .  c  om*/
        fahrgemeinschaft = (Connector) Class.forName(FAHRGEMEINSCHAFT).newInstance();
        fahrgemeinschaft.setContext(this);
        gplaces = (Connector) Class.forName(GPLACES).newInstance();
        gplaces.setContext(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
    search = new Search(getContext());
    resolve = new Resolve(getContext());
    publish = new Publish(getContext());
    myrides = new Myrides(getContext());
    retries = new HashMap<Long, Integer>();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.registerOnSharedPreferenceChangeListener(this);
    onSharedPreferenceChanged(prefs, VERBOSE);
    cleanUp(prefs);
    super.onCreate();
}

From source file:com.cssweb.android.quote.QuoteDetail.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    HandlerThread mHandlerThread = new HandlerThread("CSSWEB_THREAD");
    mHandlerThread.start();
    mHandler = new MessageHandler(mHandlerThread.getLooper());

    setContentView(R.layout.zr_quote_price);
    initTitle(R.drawable.njzq_title_left_back, 0, "");
    Bundle bundle = getIntent().getExtras();
    this.exchange = bundle.getString("exchange");
    this.stockcode = bundle.getString("stockcode");
    this.stocktype = bundle.getString("stocktype");
    this.type = NameRule.getSecurityType(exchange, stockcode);
    if (stocktype == null || stocktype.equals(""))
        stocktype = NameRule.getStockType(type);
    table_1 = (TableLayout) findViewById(R.id.zr_rt_tableview_1);
    setTitleText(getResources().getString(R.string.cjmx_title));
    customScrollView = (CustomScrollView) findViewById(R.id.zr_htable_vscroll);
    customScrollView.setOnTouchListener(this);
    customScrollView.setGestureDetector(gestureDetector);
}