Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6751993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:59:33+00:00 2026-05-26T12:59:33+00:00

I have this code: public class VoiceActivity extends Activity implements OnClickListener { private TextView

  • 0

I have this code:

public class VoiceActivity extends Activity implements OnClickListener {

private TextView mText;
private SpeechRecognizer sr;
private static final String TAG = "MyActivity";
public String str;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button speakButton = (Button) findViewById(R.id.speakButton);
    mText = (TextView) findViewById(R.id.textView1);

    speakButton.setOnClickListener(this);
    sr = SpeechRecognizer.createSpeechRecognizer(this);
    sr.setRecognitionListener(new listener());
}

class listener implements RecognitionListener {
    public void onReadyForSpeech(Bundle params) {
        Log.d(TAG, "onReadyForSpeech");
    }

    public void onBeginningOfSpeech() {
        Log.d(TAG, "onBeginningOfSpeech");
    }

    public void onRmsChanged(float rmsdB) {
        Log.d(TAG, "onRmsChanged");
    }

    public void onBufferReceived(byte[] buffer) {
        Log.d(TAG, "onBufferReceived");
    }

    public void onEndOfSpeech() {
        Log.d(TAG, "onEndofSpeech");
    }

    public void onError(int error) {
        Log.d(TAG, "error " + error);
        mText.setText("error " + error);
    }

    public void onResults(Bundle results) {
        str = new String();
        Log.d(TAG, "onResults " + results);
        ArrayList<String> data = results
                .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
        for (int i = 0; i < data.size(); i++) {
            Log.d(TAG, "result " + data.get(i));
            str += data.get(i);
        }

        mText.setText("results: " + str);

    }

    public void onPartialResults(Bundle partialResults) {
        Log.d(TAG, "onPartialResults");
    }

    public void onEvent(int eventType, Bundle params) {
        Log.d(TAG, "onEvent " + eventType);
    }
}

public void onClick(View v) {
    if (v.getId() == R.id.speakButton) {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.moc");
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
        sr.startListening(intent);
    }
}

}

How to make an automatic transition to another Activity after recognition voice (press button – say – open next Activity and result in it)? In my example, it says error in line

intent.setClass (this, SecondActivity.class).

Example:

public void onResults(Bundle results) {
    str = new String();
    Log.d(TAG, "onResults " + results);
    ArrayList<String> data = results
            .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
    for (int i = 0; i < data.size(); i++) {
        Log.d(TAG, "result " + data.get(i));
        str += data.get(i);
    }
    Intent intent = new Intent();
    Bundle b = new Bundle();
        b.putString("StrID", str);
        intent.putExtras(b);
    intent.setClass(this, SecondActivity.class);
    startActivity(intent);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:59:34+00:00Added an answer on May 26, 2026 at 12:59 pm

    you should relpace the this with VoiceActivity.this , because the this is refering the the listener instance not of the context of your activity :

    intent.setClass (VoiceActivity.this, SecondActivity.class);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code fragment: public static class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {
I have this code: public class Chronom extends Activity { Chronometer mChronometer; ProgressBar progre;
I have this code: public class Home extends Activity{ @Override public void onCreate(Bundle savedInstanceState)
I have this code: public class Window extends JFrame { public Window(){ ... JButton
Okay, so i have this code i wrote: class Connection { public static StreamWriter
I have written this piece of code public class Test{ public static void main(String[]
For instance I have this bit of code public class ProductService{ private IProductDataSource _dataSource
I have this code: public partial class FrmPrincipal : Form { private Image imagen;
I have this code: MainActivity: public class MainActivity extends ActivityGroup In MainActivity, I use
I wrote this code: public class FileViewer extends JPanel implements ActionListener { /** *

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.