Android Open Source - ServicesTutorial Thread Utils






From Project

Back to project page ServicesTutorial.

License

The source code is released under:

Apache License

If you think the Android project ServicesTutorial listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.yanlu.android.services.app.utils;
/* w  ww . j ava2 s . c  o m*/
import android.os.Bundle;
import android.util.Log;

/**
 * User: captain_miao
 * Date: 14-5-15
 * Time: ????5:16
 */
public class ThreadUtils {
    public static long getThreadId() {
        Thread t = Thread.currentThread();
        return t.getId();
    }

    public static String getThreadSignature() {
        Thread t = Thread.currentThread();
        long l = t.getId();
        String name = t.getName();
        long p = t.getPriority();
        String gname = t.getThreadGroup().getName();
        return (name
                + ":(id)" + l
                + ":(priority)" + p
                + ":(group)" + gname);
    }

    public static void logThreadSignature() {
        Log.d("ThreadUtils", getThreadSignature());
    }

    public static void sleepForInSecs(int secs) {
        try {
            Thread.sleep(secs * 1000);
        } catch (InterruptedException x) {
            throw new RuntimeException("interrupted", x);
        }
    }

    //The following two methods are used by worker threads //that we will introduce later.
    public static Bundle getStringAsABundle(String message) {
        Bundle b = new Bundle();
        b.putString("message", message);
        return b;
    }

    public static String getStringFromABundle(Bundle b) {
        return b.getString("message");
    }
}




Java Source Code List

com.yanlu.android.services.app.MainActivity.java
com.yanlu.android.services.app.service.BackgroundService.java
com.yanlu.android.services.app.service.HandlerService.java
com.yanlu.android.services.app.service.MyIntentService.java
com.yanlu.android.services.app.service.StockQuoteService.java
com.yanlu.android.services.app.utils.DeferWorkHandler.java
com.yanlu.android.services.app.utils.ThreadUtils.java