Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to display all running tasks as a checkbox list in Android
    text
    copied!<p>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.</p> <p>here is my code:-</p> <pre><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&lt;String, String&gt; item = new HashMap&lt;String, String&gt;(); item.put("Process", processName); item.put("Name", processText); list.add(item); } public void loadTasks() { try { List&lt;ActivityManager.RunningAppProcessInfo&gt; tasks = am.getRunningAppProcesses(); int numOfTasks = tasks.size(); for(int i = 0; i &lt; 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); } } </code></pre> <p>I have set all the permissions but still getting force close error please help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload