• 监控Activity的启动等状态--- 源码级


    1.代码

    参见:http://stackoverflow.com/questions/9452549/monitoring-the-recent-apps

    private void setActivityController() {
        IActivityManager am = ActivityManagerNative.getDefault();
        try {
            am.setActivityController(new ActivityController());
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
    
    
    
    
    public class ActivityController extends IActivityController.Stub {
    
    private static final String TAG = ActivityController.class.getSimpleName();
    
    @Override
    public boolean activityResuming(String pkg) throws RemoteException {
        Log.e(TAG, "activityResuming -- "+pkg);
        return true;
    }
    
    @Override
    public boolean activityStarting(Intent intent, String pkg)
            throws RemoteException {
        Log.e(TAG, "activityStarting -- "+pkg+" intent="+intent);
        return true;
    }
    
    @Override
    public boolean appCrashed(String processName, int pid, String shortMsg, String longMsg,
            long timeMillis, String stackTrace) throws RemoteException {
        Log.e(TAG, "appCrashed -- "+processName);
        return true;
    }
    
    @Override
    public int appEarlyNotResponding(String processName, int pid, String annotation)
            throws RemoteException {
        Log.e(TAG, "appEarlyNotResponding -- "+processName);
        return 0;
    }
    
    @Override
    public int appNotResponding(String processName, int pid, String processStats)
            throws RemoteException {
        Log.e(TAG, "processName -- "+processName);
        return 0;
    }
    }

    2.需要申明权限:

        <uses-permission android:name="android.permission.SET_ACTIVITY_WATCHER"/>
  • 相关阅读:
    winform最大化后不遮挡任务栏
    TabControl控件重绘
    EXT gridPanel 添加图片
    好记性不如烂笔头——double
    好记性不如烂笔头——datagridview相关
    datagridview合并相同单元格
    datagridview问题
    Linux折腾记
    TSC打印机使用教程终极版
    在线直播流测试地址
  • 原文地址:https://www.cnblogs.com/mengshu-lbq/p/4077304.html
Copyright © 2020-2023  润新知