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"/>

 

相关文章:

  • 2022-12-23
  • 2022-02-20
  • 2021-07-21
  • 2022-12-23
猜你喜欢
  • 2022-02-13
  • 2021-05-24
  • 2021-06-08
  • 2021-12-18
  • 2021-10-07
  • 2021-07-06
  • 2022-12-23
相关资源
相似解决方案