打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
【转】Android中的PID,UID,TID

Android中的PID,UID,TID

分类: Android 177人阅读 评论(1) 收藏 举报

Source code:

  1. package com.inanwong.main;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.os.Process;  
  6. import android.util.Log;  
  7.   
  8. public class MainActivity extends Activity {  
  9.   
  10.     private static final String TAG = MainActivity.class.getSimpleName();  
  11.   
  12.     /** Called when the activity is first created. */  
  13.     @Override  
  14.     public void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.         setContentView(R.layout.main);  
  17.   
  18.         /** 
  19.          * Returns the identifier of this process's user. 
  20.          */  
  21.         Log.e(TAG, "Process.myUid() = " + Process.myUid());  
  22.   
  23.         /** 
  24.          * Returns the identifier of this process, which can be used with 
  25.          * killProcess and sendSignal. 
  26.          */  
  27.         Log.e(TAG, "Process.myPid() = " + Process.myPid());  
  28.   
  29.         /** 
  30.          * Returns the identifier of the calling thread, which be used with 
  31.          * setThreadPriority(int, int). 
  32.          */  
  33.         Log.e(TAG, "Process.myTid() = " + Process.myTid());  
  34.   
  35.         /** 
  36.          * Returns the thread's identifier. The ID is a positive long generated 
  37.          * on thread creation, is unique to the thread, and doesn't change 
  38.          * during the lifetime of the thread; the ID may be reused after the 
  39.          * thread has been terminated. 
  40.          */  
  41.         Log.e(TAG, "Thread.currentThread().getId() = "  
  42.                 + Thread.currentThread().getId());  
  43.         Log.e(TAG, "getMainLooper().getThread().getId() = "  
  44.                 + getMainLooper().getThread().getId());  
  45.   
  46.         /** 
  47.          * Returns the thread's identifier. The ID is a positive long generated 
  48.          * on thread creation, is unique to the thread, and doesn't change 
  49.          * during the lifetime of the thread; the ID may be reused after the 
  50.          * thread has been terminated. 
  51.          */  
  52.         Log.e(TAG,  
  53.                 "((getApplication().getMainLooper()).getThread()).getId() = "  
  54.                         + ((getApplication().getMainLooper()).getThread())  
  55.                                 .getId());  
  56.   
  57.         /** 
  58.          * Return the identifier of the task this activity is in. This 
  59.          * identifier will remain the same for the lifetime of the activity. 
  60.          */  
  61.         Log.e(TAG, "getTaskId() = " + getTaskId());  
  62.   
  63.         /** 
  64.          * The kernel user-ID that has been assigned to this application; 
  65.          * currently this is not a unique ID (multiple applications can have the 
  66.          * same uid). 
  67.          */  
  68.         Log.e(TAG, "getApplicationInfo().uid = " + getApplicationInfo().uid);  
  69.   
  70.         /** 
  71.          * The name of the process this application should run in. From the 
  72.          * "process" attribute or, if not set, the same as packageName. 
  73.          */  
  74.         Log.e(TAG, "getApplicationInfo().processName = "  
  75.                 + getApplicationInfo().processName);  
  76.   
  77.         new Thread(new Runnable() {  
  78.   
  79.             @Override  
  80.             public void run() {  
  81.                 // TODO Auto-generated method stub  
  82.                 Log.e(TAG, "Thread.currentThread().getId() = "  
  83.                         + Thread.currentThread().getId());  
  84.             }  
  85.         }).start();  
  86.   
  87.     }  
  88. }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android中使用多线程的各种姿势
android的Handler - 程序员之路 - 博客园
androidhandler多线程demo
EventBus事件总线
PC客户端与Android服务端的Socket同步通信(USB) - 吴家大少少的专栏 -...
Android 中三种使用线程的方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服