title: Android startActivityForResult request code different than given when starting google voice-to-text
body: <p>In my app, I am trying to start google voice-to-text using RecognizerIntent from a fragment. The value of the request code was given 1010 but on the startActivityForResult the request code returned was 197618.</p>
  
  <p>The request varable has been set as:</p>
  
  <pre><code>// static result code, random integer
  public static final int REQUEST_CODE_VOICE = 1010;
  
  // set intent for recognize speech
  Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
  </code></pre>
  
  <p>onActivityCreated method of fragment, where intent has been started:</p>
  
  <pre><code>public void onActivityCreated(@Nullable Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
  
      // put language
      //intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
      intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
      //intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
      intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
      intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
              getString(R.string.speech_prompt));
  
      // tap button on click listener
      btnTap.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              try {
                  // start activity
                  Log.d("onActivityResult", "voice activity started");
                  startActivityForResult(intent, REQUEST_CODE_VOICE);
                  Log.d("onActivityResult", "voice activity finished");
              } catch(ActivityNotFoundException e) {
                  // the device does not support android speech
                  showToast("Your Device Does Not Support Speech Recognition!");
              }
          }
      });
  }
  </code></pre>
  
  <p>Here is the onActivityResult method at MainActivity</p>
  
  <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      Log.d("onActivityResult", "request: "+requestCode+", result: "+resultCode);
  
      switch(requestCode) {
          // Speech to Text
          case VoiceControllerFragment.REQUEST_CODE_VOICE:
              // get the results
              ArrayList&lt;String&gt; text
                      = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
              // show results
              TextView tvRecognizedText = (TextView) findViewById(R.id.tv_recognized_text);
              // tmp string
              //String tmpStr = "";
              tvRecognizedText.setText( "Success: " );
  
              Log.d("onActivityResult voice", "result: "+RESULT_OK);
  
              if(resultCode == RESULT_OK &amp;&amp; data != null) {
                  // concatenate all results
                  for(String str : text) {
                      tvRecognizedText.setText( tvRecognizedText.getText().toString() + str );
                  }
                  Log.d("speech", text.get(0));
              } else {
                  tvRecognizedText.setText( "Sorry! Unrecognizable speech.\nTry again!!" );
              }
              break;
      }
  }
  </code></pre>
  
  <p>Here is the log I got:</p>
  
  <pre><code>04-10 23:11:13.005  29915-29915/? D/onActivityResult﹕ voice activity started
  04-10 23:11:13.065  29915-29915/? D/onActivityResult﹕ voice activity finished
  04-10 23:11:24.855  29915-29915/? D/onActivityResult﹕ request: 197618, result: -1
  </code></pre>
  
  <p>Tested in:
  Samsung Galaxy S2,
  JellyBean</p>
  
  <p>ref: 
  <a href="http://viralpatel.net/blogs/android-speech-to-text-api/" rel="nofollow">http://viralpatel.net/blogs/android-speech-to-text-api/</a>
  <a href="http://www.androidhive.info/2014/07/android-speech-to-text-tutorial/" rel="nofollow">http://www.androidhive.info/2014/07/android-speech-to-text-tutorial/</a></p>