I am trying to display all running tasks as a check box list so i can select any of these tasks but every time i try to run it on emulator, its giving me forceclose error.
here is my code:-
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);
}
}
I have set all the permissions but still getting force close error please help.
change your perspective to DDMS and post some error log to tell us what kind of error is that. It’s important to look at the debug log to figure out what kind of errors you are facing.