-1

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);
Faheem
  • 509
  • 2
  • 7
  • 23
  • 1
    Why don't you include your logcat? Meanwhile, do you have the `GET_TASKS` permission in your manifest? – 323go May 12 '14 at 04:41

1 Answers1

0

You're lacking the GET_TASKS permission, and you would then see a SecurityException when invoking getRunningTasks(). As you're not catching the exception, your app will crash.

323go
  • 14,143
  • 6
  • 33
  • 41