Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to start an application in the way I am trying?
    text
    copied!<p>I am currently making an Android launcher and have spent a lot of time on Stackoverflow on how to go about doing different things. However I have hit a snag with opening applications from my own. The code I used was pieced together from other questions on this topic. I now have a list of installed apps, but when clicked, my own app is reopened. I figure I am using the wrong intent in the wrong way but do not know how to fix the problem. So my questions is: What would be a better way of opening a selected app? Below is the code that was used. NOTE: I am a beginner in coding.</p> <pre><code>PackageManager pm = this.getPackageManager(); Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); List &lt; String &gt; myList = new ArrayList &lt; String &gt; (); ArrayList &lt; ResolveInfo &gt; list = (ArrayList &lt; ResolveInfo &gt; ) pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED); for (ResolveInfo rInfo: list) { System.out.println("Installed Applications " + rInfo.activityInfo.applicationInfo.loadIcon(pm).toString() + rInfo.activityInfo.applicationInfo.loadLabel(pm).toString()); myList.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString()); } ListView lists = (ListView) findViewById(R.id.content); ArrayAdapter &lt; String &gt; aa = new ArrayAdapter &lt; String &gt; (this, android.R.layout.simple_list_item_1, myList); lists.setAdapter(aa); lists.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView &lt;? &gt; parent, View view, int position, long id) { Intent i = new Intent("android.intent.action.MAIN"); i.addCategory("android.intent.category.LAUNCHER"); PackageManager pm = getPackageManager(); i = pm.getLaunchIntentForPackage(getPackageName()); startActivity(i); } }); </code></pre>
 

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