I have written the following code in a service but my application immediately craches. I have tested the code in the main activity and it works fine, but when I write this code in a service, it crashes. Specifically second line is making it crash.
ActivityManager mngr = (ActivityManager) getSystemService( ACTIVITY_SERVICE );
List<ActivityManager.RunningTaskInfo> taskList = mngr.getRunningTasks(2);