• 监控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"/>
  • 相关阅读:
    P3387 【模板】缩点 tarjan
    P2831 愤怒的小鸟 状压dp
    交流帖
    P3959 宝藏 模拟退火。。。
    B1060 [ZJOI2007]时态同步 dfs
    P1850 换教室 概率dp
    树链刨分(待修改)
    B3403 [Usaco2009 Open]Cow Line 直线上的牛 deque
    B3402 [Usaco2009 Open]Hide and Seek 捉迷藏 最短路
    B5248 [2018多省省队联测]一双木棋 状压dp
  • 原文地址:https://www.cnblogs.com/mengshu-lbq/p/4077304.html
Copyright © 2020-2023  润新知