Android 開發 知曉各種id信息 獲取線程ID、activityID、內核ID


        /**
         * Returns the identifier of this process's user.
         * 返回此進程的用戶的標識符。
         */
        Log.e(TAG, "Process.myUid() = " + android.os.Process.myTid());

        /**
         * Returns the identifier of this process, which can be used with
         * killProcess and sendSignal.
         * 返回此進程的標識符,可用於進程和發送信號。
         */
        Log.e(TAG, "Process.myPid() = " + android.os.Process.myPid());

        /**
         * Returns the identifier of the calling thread, which be used with
         * setThreadPriority(int, int).
         * 返回調用線程的標識符,該標識符與StTeRead優先級(int,int)。
         */
        Log.e(TAG, "Process.myTid() = " + android.os.Process.myTid());

        /**
         * Returns the thread's identifier. The ID is a positive long generated
         * on thread creation, is unique to the thread, and doesn't change
         * during the lifetime of the thread; the ID may be reused after the
         * thread has been terminated.
         * 返回線程的標識符。ID是正長生成的關於線程創建,對於線程是唯一的,並且不會改變。
         * 在線程的生存期內,ID可以在線程已被終止。
         */

        //返回當前線程的id
        Log.e(TAG, "Thread.currentThread().getId() = "
                + Thread.currentThread().getId());
        //返回主線程的id
        Log.e(TAG, "getMainLooper().getThread().getId() = "
                + getMainLooper().getThread().getId());

        //返回當前應用的主線程id
        Log.e(TAG,
                        "((getApplication().getMainLooper()).getThread()).getId() = "
                                + ((getApplication().getMainLooper()).getThread())
                                .getId());

        /**
         * Return the identifier of the task this activity is in. This
         * identifier will remain the same for the lifetime of the activity.
         * 返回此活動正在執行的任務的標識符。這個標識符對於活動的生存期將保持不變。
         */
        //返回activity任務棧的id
        Log.e(TAG, "getTaskId() = " + getTaskId());

        /**
         * The kernel user-ID that has been assigned to this application;
         * currently this is not a unique ID (multiple applications can have the
         * same uid).
         * 已分配給該應用程序的內核用戶ID;這不是一個唯一的ID(多個應用程序可以有相同的UID)。
         */
        Log.e(TAG, "getApplicationInfo().uid = " + getApplicationInfo().uid);

        /**
         * The name of the process this application should run in. From the
         * "process" attribute or, if not set, the same as packageName.
         * 此應用程序應運行的進程的名稱。從“進程”屬性,或如果沒有設置,與PACKAGEName相同。
         */
        Log.e(TAG, "getApplicationInfo().processName = "
                + getApplicationInfo().processName);

        /**
         * 得到當前activity的信息
         */
        Log.e(TAG, "Activity.toString:"+this.toString());
        

        new Thread(new Runnable() {

            @Override
            public void run() {
                //返回當前線程的id
                // TODO Auto-generated method stub
                Log.e(TAG, "Thread.currentThread().getId() = "
                        + Thread.currentThread().getId());
            }
        }).start();

 

 

結果:

2018-08-28 15:00:42.887 29813-29813/com.example.user.demo E/EventBusDemoActivity: Process.myUid() = 29813
2018-08-28 15:00:42.887 29813-29813/com.example.user.demo E/EventBusDemoActivity: Process.myPid() = 29813
2018-08-28 15:00:42.887 29813-29813/com.example.user.demo E/EventBusDemoActivity: Process.myTid() = 29813
2018-08-28 15:00:42.888 29813-29813/com.example.user.demo E/EventBusDemoActivity: Thread.currentThread().getId() = 1
2018-08-28 15:00:42.888 29813-29813/com.example.user.demo E/EventBusDemoActivity: getMainLooper().getThread().getId() = 1
2018-08-28 15:00:42.888 29813-29813/com.example.user.demo E/EventBusDemoActivity: ((getApplication().getMainLooper()).getThread()).getId() = 1
2018-08-28 15:00:42.888 29813-29813/com.example.user.demo E/EventBusDemoActivity: getTaskId() = 113
2018-08-28 15:00:42.888 29813-29813/com.example.user.demo E/EventBusDemoActivity: getApplicationInfo().uid = 10085
2018-08-28 15:00:42.888 29813-29813/com.example.user.demo E/EventBusDemoActivity: getApplicationInfo().processName = com.example.user.demo
2018-08-28 15:00:42.888 29813-29813/com.example.user.demo E/EventBusDemoActivity: Activity.toString:com.example.user.demo.EventBusDemoActivity$1@d500b7a
2018-08-28 15:00:42.888 29813-29832/com.example.user.demo E/EventBusDemoActivity: Thread.currentThread().getId() = 885

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM