문제

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);
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top