title: Android: Using ACTION_PICK_ACTIVITY with AppWidget to determine which application to open on press
body: <p>I'm trying to allow the user to choose which app to open when they press on my widget. It seems the way to do this is to use the ACTION_PICK_ACTIVITY and somehow save the value they've picked.</p>
  
  <p><a href="http://www.openintents.org/en/node/263" rel="nofollow">http://www.openintents.org/en/node/263</a> seems helpful, but does not show how to extract the data from the Intent in able to save it for future Intent creation.</p>
  
  <p><strong>How can I easily allow the user to pick from a list of applications installed on his or her phone and then save the chosen package/class for future intent creation?</strong></p>
  
  <pre><code>View.OnClickListener activity_picker_listener = new View.OnClickListener(){
      @Override
      public void onClick(View v){
          // Pick an application
          Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
          mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  
          Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
          pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
          startActivityForResult(pickIntent, 0);
      }
  };
  
  // The result is obtained in onActivityResult:
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     if (data != null) {
         // save the application that we just picked
     }
  }
  </code></pre>