当前位置:操作系统 > 安卓/Android >>

线程实用程序

import android.os.Bundle; 
import android.util.Log; 
 
public class Utils { 
    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 e) { 
            throw new RuntimeException("interrupted", e); 
        } 
    } 
 
    public static Bundle getStringAsABundle(String message) { 
        Bundle b = new Bundle(); 
        b.putString("message", message); 
        return b; 
    } 
 
    public static String getSteingFromABundle(Bundle b) { 
        return b.getString("message"); 
    } 


摘自 Geek Diaries
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,