android中进程状态,状态机是怎样变化的?

frameworks/base/core/java/android/app/ActivityManager.java


    /** @hide Process does not exist. */
    public static final int PROCESS_STATE_NONEXISTENT = -1;


    /** @hide Process is a persistent system process. */
    public static final int PROCESS_STATE_PERSISTENT = 0;


    /** @hide Process is a persistent system process and is doing UI. */
    public static final int PROCESS_STATE_PERSISTENT_UI = 1;


    /** @hide Process is hosting the current top activities.  Note that this covers
     * all activities that are visible to the user. */
    public static final int PROCESS_STATE_TOP = 2;


    /** @hide Process is hosting a foreground service due to a system binding. */
    public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 3;


    /** @hide Process is hosting a foreground service. */
    public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4;


    /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */
    public static final int PROCESS_STATE_TOP_SLEEPING = 5;


    /** @hide Process is important to the user, and something they are aware of. */
    public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6;


    /** @hide Process is important to the user, but not something they are aware of. */
    public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 7;


    /** @hide Process is in the background running a backup/restore operation. */
    public static final int PROCESS_STATE_BACKUP = 8;


    /** @hide Process is in the background, but it can't restore its state so we want
     * to try to avoid killing it. */
    public static final int PROCESS_STATE_HEAVY_WEIGHT = 9;


    /** @hide Process is in the background running a service.  Unlike oom_adj, this level
     * is used for both the normal running in background state and the executing
     * operations state. */
    public static final int PROCESS_STATE_SERVICE = 10;


    /** @hide Process is in the background running a receiver.   Note that from the
     * perspective of oom_adj receivers run at a higher foreground level, but for our
     * prioritization here that is not necessary and putting them below services means
     * many fewer changes in some process states as they receive broadcasts. */
    public static final int PROCESS_STATE_RECEIVER = 11;


    /** @hide Process is in the background but hosts the home activity. */
    public static final int PROCESS_STATE_HOME = 12;


    /** @hide Process is in the background but hosts the last shown activity. */
    public static final int PROCESS_STATE_LAST_ACTIVITY = 13;


    /** @hide Process is being cached for later use and contains activities. */
    public static final int PROCESS_STATE_CACHED_ACTIVITY = 14;


    /** @hide Process is being cached for later use and is a client of another cached
     * process that contains activities. */
    public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 15;


    /** @hide Process is being cached for later use and is empty. */

    public static final int PROCESS_STATE_CACHED_EMPTY = 16;



这里关注进程状态的变化, service: ProcessObserver 可以展示进程状态的变化,展示的就是上面的状态,

Native进程,可以被监测到吗?

使用ProcessObserver 是为判断输入法是否在当前界面。

输入法界面不在当前时android.process.acore (pid 2745)的状态为Perceptible

    95420 kB:       0 kB: Visible
                3527 kB:     460 kB: com.android.smspush (pid 21018)
   193521 kB:       0 kB: Perceptible)
               52848 kB:     404 kB: android.process.acore (pid 2745)
               38753 kB:      60 kB: com.baidu.input_mi (pid 20542)

输入法界面在当前时com.baidu.input_mi (pid 20542)的状态为Visible

   154008 kB:       0 kB: Visible
               52385 kB:      60 kB: com.baidu.input_mi (pid 20542)

   153782 kB:       0 kB: Perceptible
               52754 kB:     404 kB: android.process.acore (pid 2745)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值