我正在尝试将所有正在运行的任务显示为复选框列表,以便我可以选择任何这些任务,但每次我尝试在模拟器上运行它时,它会给我forceclose错误。
这是我的代码: -
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
myContext = this;
this.loadTasks();
}
public void addItem(String processName, String processText)
{
HashMap<String, String> item = new HashMap<String, String>();
item.put("Process", processName);
item.put("Name", processText);
list.add(item);
}
public void loadTasks()
{
try
{
List<ActivityManager.RunningAppProcessInfo> tasks = am.getRunningAppProcesses();
int numOfTasks = tasks.size();
for(int i = 0; i < numOfTasks; i++)
{
ActivityManager.RunningAppProcessInfo task = tasks.get(i);
try
{
PackageInfo myPInfo = getPackageManager().getPackageInfo(task.processName, 0);
addItem(task.processName, myPInfo.applicationInfo.loadLabel(getPackageManager()).toString());
}
catch (PackageManager.NameNotFoundException ne)
{
}
}
}
catch (SecurityException se)
{
}
SimpleAdapter notes = new SimpleAdapter(myContext, list, android.R.layout.simple_list_item_multiple_choice, new String[] {"Name", "Process"}, new int[] {android.R.id.text1, android.R.id.text2});
setListAdapter(notes);
}
}
我已经设置了所有权限,但仍然会收到强制关闭错误,请帮忙。
答案 0 :(得分:0)
将您的观点更改为DDMS并发布一些错误日志以告诉我们这是什么类型的错误。查看调试日志以确定您所面临的错误类型非常重要。