1. Download our Official Android App: Forums for Android!

Apps Need loop code or ?

Discussion in 'Android Development' started by Flinx, Dec 18, 2011.

  1. Flinx

    Flinx Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    2
    Joined:
    Dec 10, 2011

    Dec 10, 2011
    2
    0
    25
    I have problem with voice recognition code, works first part but then uses 1st 'results' in the google search method... ugh..

    code:

    if (results.contains("play")){


    Handler handler4 = new Handler();
    handler4.postDelayed(new Runnable() {
    public void run() {

    mTts.speak("Play What?", TextToSpeech.QUEUE_FLUSH, null);
    }
    }, 1000);

    Handler handler5 = new Handler();
    handler5.postDelayed(new Runnable() {
    public void run() {

    Intent g = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

    g.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    g.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak UP!");
    g.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);


    final ArrayList<String> results1 = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    startActivityForResult(g, check);

    Handler handler4 = new Handler();
    handler4.postDelayed(new Runnable() {
    public void run() {

    Intent sgoogle = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com/search?q=%22"+results1+"%22"));
    startActivityForResult(sgoogle, check);
    }
    }, 12000);

    }
    }, 5000);

    It is suppose to react to word 'play' which it does, then TTS ask "Play what?", which it does.. and then open recognizer, which it does.. then take results to google search, which is where its broken.. because it uses the 1st results of 'play' ..

    Thank you in advance.
    Flinx
     

    Advertisement

  2. jiminaus

    jiminaus Well-Known Member
    Rank:
    None
    Points:
    63
    Posts:
    190
    Joined:
    Oct 27, 2011

    Oct 27, 2011
    190
    36
    63
    Sydney, Australia
    I think you're doing too much in one place. As I understand it, startActivityForResult will not block while the activity runs. It will return immediately. You need to wait for your onActivityResult(int, int, Intent) to be called.

    Take a look at Starting Activities and Getting Results.
     

Share This Page

Loading...