text-to-speech service connection leaked / voice recognition not properly working
My app uses both voice recognition and text-to-speech extensively throughout. I had it working and then I started to change the code and add methods instead of calling the same intent several times. Unfortunately I closed out of eclipse before I ran on my android device and now I have several problems in the CatLog and I can't revert back to my earlier save. I need some help analyzing my CatLog and fixing these problems. I have included it as well as all of the recently edited java files.



        07-31 08:35:01.902: E/ActivityThread(26448): Activity com.example.com.proto1.mainj has leaked ServiceConnection android.speech.tts.TextToSpeech$1@408e7fa0 that was originally bound here
    07-31 08:35:01.902: E/ActivityThread(26448): android.app.ServiceConnectionLeaked: Activity com.example.com.proto1.mainj has leaked ServiceConnection android.speech.tts.TextToSpeech$1@408e7fa0 that was originally bound here
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:932)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:827)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.ContextImpl.bindService(ContextImpl.java:1109)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:517)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:483)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at com.example.com.proto1.mainj.onActivityResult(mainj.java:83)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.Activity.dispatchActivityResult(Activity.java:4581)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:2817)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:2864)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.ActivityThread.access$1000(ActivityThread.java:122)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1057)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.os.Looper.loop(Looper.java:132)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.ActivityThread.main(ActivityThread.java:4126)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at java.lang.reflect.Method.invokeNative(Native Method)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at java.lang.reflect.Method.invoke(Method.java:491)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at dalvik.system.NativeStart.main(Native Method)
    07-31 08:35:09.852: I/TextToSpeech.java - speak(26448): speak text of length 9
    07-31 08:35:10.032: D/CLIPBOARD(26448): Hide Clipboard dialog at Starting input: finished by someone else... !
    07-31 08:35:31.152: I/TextToSpeech.java - speak(26448): speak text of length 5
    07-31 08:35:31.212: I/ApplicationPackageManager(26448): cscCountry is not German : VZW
    07-31 08:35:31.242: D/dalvikvm(26448): GC_FOR_ALLOC freed 2843K, 27% free 8111K/11079K, paused 21ms
    07-31 08:35:31.242: I/dalvikvm-heap(26448): Grow heap (frag case) to 10.659MB for 2764816-byte allocation
    07-31 08:35:31.282: D/dalvikvm(26448): GC_FOR_ALLOC freed <1K, 3% free 10810K/11079K, paused 21ms
    07-31 08:35:31.312: D/dalvikvm(26448): GC_CONCURRENT freed 0K, 3% free 10810K/11079K, paused 2ms+2ms
    07-31 08:35:31.582: I/TextToSpeech.java(26448): initTts() successfully bound to service
    07-31 08:35:36.522: I/TextToSpeech.java - speak(26448): speak text of length 22
    07-31 08:35:39.192: I/TextToSpeech.java - speak(26448): speak text of length 5
    07-31 08:35:39.222: I/ApplicationPackageManager(26448): cscCountry is not German : VZW
    07-31 08:35:39.322: I/TextToSpeech.java(26448): initTts() successfully bound to service
    07-31 08:35:42.772: I/TextToSpeech.java - speak(26448): speak text of length 14
    07-31 08:35:42.822: I/ApplicationPackageManager(26448): cscCountry is not German : VZW
    07-31 08:35:45.132: D/CLIPBOARD(26448): Hide Clipboard dialog at Starting input: finished by someone else... !
    07-31 08:35:45.562: E/ActivityThread(26448): Activity com.example.com.proto1.Infoactive has leaked ServiceConnection android.speech.tts.TextToSpeech$1@40cc9258 that was originally bound here
    07-31 08:35:45.562: E/ActivityThread(26448): android.app.ServiceConnectionLeaked: Activity com.example.com.proto1.Infoactive has leaked ServiceConnection android.speech.tts.TextToSpeech$1@40cc9258 that was originally bound here
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:932)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:827)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.ContextImpl.bindService(ContextImpl.java:1109)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:517)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:483)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at com.example.com.proto1.Infoactive.onActivityResult(Infoactive.java:193)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.Activity.dispatchActivityResult(Activity.java:4581)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:2817)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:2864)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.ActivityThread.access$1000(ActivityThread.java:122)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1057)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.os.Looper.loop(Looper.java:132)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.ActivityThread.main(ActivityThread.java:4126)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at java.lang.reflect.Method.invokeNative(Native Method)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at java.lang.reflect.Method.invoke(Method.java:491)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at dalvik.system.NativeStart.main(Native Method)
    07-31 08:35:45.582: E/ActivityThread(26448): Activity com.example.com.proto1.Infoactive has leaked ServiceConnection android.speech.tts.TextToSpeech$1@40ccc2c0 that was originally bound here
    07-31 08:35:45.582: E/ActivityThread(26448): android.app.ServiceConnectionLeaked: Activity com.example.com.proto1.Infoactive has leaked ServiceConnection android.speech.tts.TextToSpeech$1@40ccc2c0 that was originally bound here
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:932)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:827)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.ContextImpl.bindService(ContextImpl.java:1109)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:517)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:483)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at com.example.com.proto1.Infoactive.onActivityResult(Infoactive.java:193)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.Activity.dispatchActivityResult(Activity.java:4581)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:2817)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:2864)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.ActivityThread.access$1000(ActivityThread.java:122)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1057)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.os.Looper.loop(Looper.java:132)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.ActivityThread.main(ActivityThread.java:4126)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at java.lang.reflect.Method.invokeNative(Native Method)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at java.lang.reflect.Method.invoke(Method.java:491)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at dalvik.system.NativeStart.main(Native Method)
    07-31 08:35:45.612: D/dalvikvm(26448): GC_CONCURRENT freed 4098K, 35% free 8188K/12423K, paused 3ms+3ms
    07-31 08:35:56.452: D/CLIPBOARD(26448): Hide Clipboard dialog at Starting input: finished by someone else... !
    07-31 08:36:06.212: D/AndroidRuntime(26448): Shutting down VM
    07-31 08:36:06.212: W/dalvikvm(26448): threadid=1: thread exiting with uncaught exception (group=0x402d0760)
    07-31 08:36:06.212: E/AndroidRuntime(26448): FATAL EXCEPTION: main
    07-31 08:36:06.212: E/AndroidRuntime(26448): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1234, result=-1, data=Intent { (has extras) }} to activity {com.example.com.proto1/com.example.com.proto1.VoiceRecognition}: java.lang.NullPointerException
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:2821)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:2864)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.ActivityThread.access$1000(ActivityThread.java:122)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1057)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.os.Looper.loop(Looper.java:132)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.ActivityThread.main(ActivityThread.java:4126)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at java.lang.reflect.Method.invokeNative(Native Method)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at java.lang.reflect.Method.invoke(Method.java:491)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at dalvik.system.NativeStart.main(Native Method)
    07-31 08:36:06.212: E/AndroidRuntime(26448): Caused by: java.lang.NullPointerException
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at com.example.com.proto1.VoiceRecognition.speakWords(VoiceRecognition.java:193)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at com.example.com.proto1.VoiceRecognition.onActivityResult(VoiceRecognition.java:155)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.Activity.dispatchActivityResult(Activity.java:4581)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:2817)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	... 11 more

    

        import android.app.Activity;
    
    /**
     * Sample code that invokes the speech recognition intent API.
     */
    public class VoiceRecognition extends Activity implements OnClickListener,
    		OnInitListener {
    
    	public static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
    
    	public ListView mList;
    	public Button speakButton;
    	// TTS object
    	public TextToSpeech myTTS;
    	// status check code
    	public int MY_DATA_CHECK_CODE = 0;
    
    	public void informationmenu() {
    		speakWords("information screen");
    		startActivity(new Intent("android.intent.action.INFOSCREEN"));
    	}
    
    	public void voicemenu() {
    		speakWords("voice recognition menu");
    		startActivity(new Intent("android.intent.action.RECOGNITIONMENU"));
    	}
    
    	public void mainmenu() {
    		speakWords("main menu");
    		startActivity(new Intent("android.intent.action.MENU"));
    	}
    
    	public void voicerecog() {
    		speakWords("speak now");
    		startActivity(new Intent("android.intent.action.SPEAK"));
    	}
    
    	/**
    	 * Called with the activity is first created.
    	 */
    	@Override
    	public void onCreate(Bundle voiceinput) {
    		super.onCreate(voiceinput);
    
    		// Inflate our UI from its XML layout description.
    		setContentView(R.layout.voice_recognition);
    
    		// check for TTS data
    		Intent checkTTSIntent = new Intent();
    		checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    		startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
    
    		// Get display items for later interaction
    
    		voiceinputbuttons();
    
    		// Check to see if a recognition activity is present
    		PackageManager pm = getPackageManager();
    		List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(
    				RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    		if (activities.size() != 0) {
    			speakButton.setOnClickListener(this);
    		} else {
    			speakButton.setEnabled(false);
    			speakButton.setText("Recognizer not present");
    		}
    	}
    
    	// setup TTS
    	public void onInit(int initStatus) {
    
    		// check for successful instantiation
    		if (initStatus == TextToSpeech.SUCCESS) {
    			if (myTTS.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE)
    				myTTS.setLanguage(Locale.US);
    		} else if (initStatus == TextToSpeech.ERROR) {
    			Toast.makeText(this, "Sorry! Text To Speech failed...",
    					Toast.LENGTH_LONG).show();
    		}
    	}
    
    	/**
    	 * Handle the click on the start recognition button.
    	 */
    
    	public void onClick(View v) {
    		startVoiceRecognitionActivity();
    	}
    
    	public void voiceinputbuttons() {
    		speakButton = (Button) findViewById(R.id.btn_speak);
    		mList = (ListView) findViewById(R.id.list);
    	}
    
    	/**
    	 * Fire an intent to start the speech recognition activity.
    	 */
    	public void startVoiceRecognitionActivity() {
    		Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    		intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
    				RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    		intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
    				"Speech recognition demo");
    		startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
    	}
    
    	/**
    	 * Handle the results from the recognition activity.
    	 */
    	@Override
    	public void onActivityResult(int requestCode, int resultCode, Intent data) {
    		if (requestCode == VOICE_RECOGNITION_REQUEST_CODE
    				&& resultCode == RESULT_OK) {
    			// Fill the list view with the strings the recognizer thought it
    			// could have heard
    			ArrayList<String> matches = data
    					.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    			mList.setAdapter(new ArrayAdapter<String>(this,
    					android.R.layout.simple_list_item_1, matches));
    			// matches is the result of voice input. It is a list of what the
    			// user possibly said.
    			// Using an if statement for the keyword you want to use allows the
    			// use of any activity if keywords match
    			// it is possible to set up multiple keywords to use the same
    			// activity so more than one word will allow the user
    			// to use the activity (makes it so the user doesn't have to
    			// memorize words from a list)
    			// to use an activity from the voice input information simply use
    			// the following format;
    			// if (matches.contains("keyword here") { startActivity(new
    			// Intent("name.of.manifest.ACTIVITY")
    
    			if (matches.contains("information || info screen || info || about")) {
    				informationmenu();
    			} else {
    				speakWords("Speak Now");
    				startVoiceRecognitionActivity();
    				if (matches.contains("home || menu || home screen")) {
    					mainmenu();
    				} else {
    					speakWords("Speak Now");
    					startVoiceRecognitionActivity();
    				}
    				if (matches.contains("speak")) {
    					voicerecog();
    				} else {
    					speakWords("Speak Now");
    					startVoiceRecognitionActivity();
    				}
    				if (matches.contains("close || stop || finish")) {
    					finish();
    				} else {
    					speakWords("Speak Now");
    					startVoiceRecognitionActivity();
    				}
    				if (matches
    						.contains("voice || recognition|| voice recognition")) {
    					voicemenu();
    				} else {
    					speakWords("Speak Now");
    					startVoiceRecognitionActivity();
    				}
    
    			}
    		}
    		super.onActivityResult(requestCode, resultCode, data);
    
    	}
    
    	// speak the user text
    	public void speakWords(String speech) {
    
    		// speak straight away
    		myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
    	}
    
    }


            import java.util.Locale;
    

    
    @SuppressWarnings("unused")
    public class mainj extends Activity implements OnInitListener {
    
    	private TextToSpeech myTTS;
    	// status check code
    	private int MY_DATA_CHECK_CODE = 0;
    
    	// setup TTS
    	public void onInit(int initStatus) {
    
    		// check for successful instantiation
    		if (initStatus == TextToSpeech.SUCCESS) {
    			if (myTTS.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE)
    				myTTS.setLanguage(Locale.US);
    		} else if (initStatus == TextToSpeech.ERROR) {
    			Toast.makeText(this, "Sorry! Text To Speech failed...",
    					Toast.LENGTH_LONG).show();
    		}
    	}
    
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.loadscreen);
    		Intent checkTTSIntent = new Intent();
    		checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    		startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
    		Thread logoTimer = new Thread() {
    			public void run() {
    				try {
    					try {
    						sleep(3000);
    						speakWords("main menu loaded");
    					} catch (InterruptedException e) {
    						e.printStackTrace();
    					}
    
    					Intent menuIntent = new Intent("android.intent.action.MENU");
    					startActivity(menuIntent);
    
    				}
    
    				finally {
    					finish();
    				}
    			}
    
    		};
    		logoTimer.start();
    	}
    
    	// speak the user text
    	private void speakWords(String speech) {
    
    		// speak straight away
    		if (myTTS != null) {
    			myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
    		}
    	}
    
    	// act on result of TTS data check
    	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    
    		if (requestCode == MY_DATA_CHECK_CODE) {
    			if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
    				// the user has the necessary data - create the TTS
    				myTTS = new TextToSpeech(this, this);
    			} else {
    				// no data - install it now
    				Intent installTTSIntent = new Intent();
    				installTTSIntent
    						.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
    				startActivity(installTTSIntent);
    			}
    		}
    	}


            import android.app.Activity;
   
    @SuppressWarnings("unused")
    public class menu extends Activity implements TextToSpeech.OnInitListener,
    		OnClickListener {
    
    	// defined
    	TextToSpeech mTts;
    	public static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
    
    	// remember to include a listview on the xml or the voice recognition code
    	// will not work
    	public ListView mList;
    	// TTS object
    	Button speakButton, infoButton, voiceButton, talkButton;
    
    	VoiceRecognition vro = new VoiceRecognition();
    	SpeakingAndroid speak = new SpeakingAndroid();
    
    	// TTS object
    	public TextToSpeech myTTS;
    	// status check code
    	public int MY_DATA_CHECK_CODE = 0;
    
    	@Override
    	protected void onCreate(Bundle aboutmenu) {
    		super.onCreate(aboutmenu);
    		setContentView(R.layout.mainx);
    
    		VoiceRecognition voiceinput = new VoiceRecognition();
    
    		// get a reference to the button element listed in the XML layout
    		speakButton = (Button) findViewById(R.id.btn_speak);
    		infoButton = (Button) findViewById(R.id.aboutbutton);
    		voiceButton = (Button) findViewById(R.id.voicebutton);
    		talkButton = (Button) findViewById(R.id.talk);
    
    		// listen for clicks
    		infoButton.setOnClickListener(this);
    		speakButton.setOnClickListener(this);
    		talkButton.setOnClickListener(this);
    
    		// check for TTS data
    		Intent checkTTSIntent = new Intent();
    		checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    		startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
    
    		// calling method
    		voiceinputbuttons();
    
    		// Check to see if a recognition activity is present
    		// if running on AVD virtual device it will give this message. The mic
    		// required only works on an actual android device//
    		PackageManager pm = getPackageManager();
    		List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(
    				RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    		if (activities.size() != 0) {
    			voiceButton.setOnClickListener(this);
    		} else {
    			voiceButton.setEnabled(false);
    			voiceButton.setText("Recognizer not present");
    		}
    
    	}
    
    	// setup TTS
    	public void onInit(int initStatus) {
    
    		// check for successful instantiation
    
    		// returns a fail statement if speech doesn't work
    		if (initStatus == TextToSpeech.SUCCESS) {
    			if (myTTS.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE)
    				myTTS.setLanguage(Locale.US);
    		} else if (initStatus == TextToSpeech.ERROR) {
    			Toast.makeText(this, "Sorry! Text To Speech failed...",
    					Toast.LENGTH_LONG).show();
    		}
    	}
    
    	// creating method
    	public void voiceinputbuttons() {
    		speakButton = (Button) findViewById(R.id.btn_speak);
    		mList = (ListView) findViewById(R.id.list);
    	}
    
    	// respond to button clicks
    	public void onClick(View v) {
    		switch (v.getId()) {
    
    		// use switch case so each button does a different thing
    		// accurately(similar to an if statement)
    		case R.id.btn_speak:
    			String words1 = speakButton.getText().toString();
    
    			// speakwords(xxxx); is the piece of code that actually calls the
    			// text to speech
    			speakWords(words1);
    			Intent voiceIntent = new Intent(
    					"android.intent.action.RECOGNITIONMENU");
    			startActivity(voiceIntent);
    			break;
    		case R.id.aboutbutton:
    			String words2 = infoButton.getText().toString();
    			speakWords(words2);
    			Intent infoIntent = new Intent("android.intent.action.INFOSCREEN");
    			startActivity(infoIntent);
    			break;
    		case R.id.voicebutton:
    			speakWords("Speak Now");
    			startVoiceRecognitionActivity(); // call for voice recognition
    												// activity
    			break;
    		case R.id.talk:
    			speakWords("This is the main menu.");
    			break;
    		}
    	}
    
    	// speak the user text
    	// setting up the speakWords code
    	public void speakWords(String speech) {
    
    		// speak straight away
    		myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
    	}
    
    	/**
    	 * Fire an intent to start the speech recognition activity.
    	 */
    	public void startVoiceRecognitionActivity() {
    		Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    		intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
    				RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    		intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
    				"Speech recognition demo");
    		startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
    	}
    
    	/**
    	 * Handle the results from the recognition activity.
    	 */
    	@Override
    	public void onActivityResult(int requestCode, int resultCode, Intent data) {
    		if (requestCode == VOICE_RECOGNITION_REQUEST_CODE
    				&& resultCode == RESULT_OK) {
    			// Fill the list view with the strings the recognizer thought it
    			// could have heard
    			ArrayList<String> matches = data
    					.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    			mList.setAdapter(new ArrayAdapter<String>(this,
    					android.R.layout.simple_list_item_1, matches));
    			// matches is the result of voice input. It is a list of what the
    			// user possibly said.
    			// Using an if statement for the keyword you want to use allows the
    			// use of any activity if keywords match
    			// it is possible to set up multiple keywords to use the same
    			// activity so more than one word will allow the user
    			// to use the activity (makes it so the user doesn't have to
    			// memorize words from a list)
    			// to use an activity from the voice input information simply use
    			// the following format;
    			// if (matches.contains("keyword here") { startActivity(new
    			// Intent("name.of.manifest.ACTIVITY")
    
    			if (matches.contains("information")) {
    				vro.informationmenu();
    			}
    			if (matches.contains("info screen")) {
    				vro.informationmenu();
    			}
    			if (matches.contains("info")) {
    				vro.informationmenu();
    			}
    			if (matches.contains("about")) {
    				vro.informationmenu();
    			}
    
    			if (matches.contains("home")) {
    				vro.mainmenu();
    			}
    			if (matches.contains("menu")) {
    				vro.mainmenu();
    			}
    			if (matches.contains("home screen")) {
    				vro.mainmenu();
    			}
    			if (matches.contains("speak")) {
    				vro.voicerecog();
    			}
    			if (matches.contains("close")) {
    				finish();
    			}
    			if (matches.contains("stop")) {
    				finish();
    			}
    			if (matches.contains("finish")) {
    				finish();
    			}
    			if (matches.contains("voice")) {
    				vro.voicemenu();
    			}
    			if (matches.contains("recognition")) {
    				vro.voicemenu();
    			}
    			if (matches.contains("voice recognition")) {
    				vro.voicemenu();
    			}
    
    		}
    
    		// still in the onActivityResult: This is for the text to speech part
    
    		if (requestCode == MY_DATA_CHECK_CODE) {
    			if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
    				// the user has the necessary data - create the TTS
    				myTTS = new TextToSpeech(this, this);
    			} else {
    				// no data - install it now
    				Intent installTTSIntent = new Intent();
    				installTTSIntent
    						.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
    				startActivity(installTTSIntent);
    			}
    		}
    
    		super.onActivityResult(requestCode, resultCode, data);
    
    	}
    
    }




text-to-speech service connection leaked / voice recognition not properly working
===

My app uses both voice recognition and text-to-speech extensively throughout. I had it working and then I started to change the code and add methods instead of calling the same intent several times. Unfortunately I closed out of eclipse before I ran on my android device and now I have several problems in the CatLog and I can't revert back to my earlier save. I need some help analyzing my CatLog and fixing these problems. I have included it as well as all of the recently edited java files.



        07-31 08:35:01.902: E/ActivityThread(26448): Activity com.example.com.proto1.mainj has leaked ServiceConnection android.speech.tts.TextToSpeech$1@408e7fa0 that was originally bound here
    07-31 08:35:01.902: E/ActivityThread(26448): android.app.ServiceConnectionLeaked: Activity com.example.com.proto1.mainj has leaked ServiceConnection android.speech.tts.TextToSpeech$1@408e7fa0 that was originally bound here
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:932)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:827)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.ContextImpl.bindService(ContextImpl.java:1109)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:517)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:483)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at com.example.com.proto1.mainj.onActivityResult(mainj.java:83)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.Activity.dispatchActivityResult(Activity.java:4581)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:2817)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:2864)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.ActivityThread.access$1000(ActivityThread.java:122)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1057)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.os.Looper.loop(Looper.java:132)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at android.app.ActivityThread.main(ActivityThread.java:4126)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at java.lang.reflect.Method.invokeNative(Native Method)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at java.lang.reflect.Method.invoke(Method.java:491)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    07-31 08:35:01.902: E/ActivityThread(26448): 	at dalvik.system.NativeStart.main(Native Method)
    07-31 08:35:09.852: I/TextToSpeech.java - speak(26448): speak text of length 9
    07-31 08:35:10.032: D/CLIPBOARD(26448): Hide Clipboard dialog at Starting input: finished by someone else... !
    07-31 08:35:31.152: I/TextToSpeech.java - speak(26448): speak text of length 5
    07-31 08:35:31.212: I/ApplicationPackageManager(26448): cscCountry is not German : VZW
    07-31 08:35:31.242: D/dalvikvm(26448): GC_FOR_ALLOC freed 2843K, 27% free 8111K/11079K, paused 21ms
    07-31 08:35:31.242: I/dalvikvm-heap(26448): Grow heap (frag case) to 10.659MB for 2764816-byte allocation
    07-31 08:35:31.282: D/dalvikvm(26448): GC_FOR_ALLOC freed <1K, 3% free 10810K/11079K, paused 21ms
    07-31 08:35:31.312: D/dalvikvm(26448): GC_CONCURRENT freed 0K, 3% free 10810K/11079K, paused 2ms+2ms
    07-31 08:35:31.582: I/TextToSpeech.java(26448): initTts() successfully bound to service
    07-31 08:35:36.522: I/TextToSpeech.java - speak(26448): speak text of length 22
    07-31 08:35:39.192: I/TextToSpeech.java - speak(26448): speak text of length 5
    07-31 08:35:39.222: I/ApplicationPackageManager(26448): cscCountry is not German : VZW
    07-31 08:35:39.322: I/TextToSpeech.java(26448): initTts() successfully bound to service
    07-31 08:35:42.772: I/TextToSpeech.java - speak(26448): speak text of length 14
    07-31 08:35:42.822: I/ApplicationPackageManager(26448): cscCountry is not German : VZW
    07-31 08:35:45.132: D/CLIPBOARD(26448): Hide Clipboard dialog at Starting input: finished by someone else... !
    07-31 08:35:45.562: E/ActivityThread(26448): Activity com.example.com.proto1.Infoactive has leaked ServiceConnection android.speech.tts.TextToSpeech$1@40cc9258 that was originally bound here
    07-31 08:35:45.562: E/ActivityThread(26448): android.app.ServiceConnectionLeaked: Activity com.example.com.proto1.Infoactive has leaked ServiceConnection android.speech.tts.TextToSpeech$1@40cc9258 that was originally bound here
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:932)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:827)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.ContextImpl.bindService(ContextImpl.java:1109)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:517)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:483)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at com.example.com.proto1.Infoactive.onActivityResult(Infoactive.java:193)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.Activity.dispatchActivityResult(Activity.java:4581)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:2817)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:2864)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.ActivityThread.access$1000(ActivityThread.java:122)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1057)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.os.Looper.loop(Looper.java:132)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at android.app.ActivityThread.main(ActivityThread.java:4126)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at java.lang.reflect.Method.invokeNative(Native Method)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at java.lang.reflect.Method.invoke(Method.java:491)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    07-31 08:35:45.562: E/ActivityThread(26448): 	at dalvik.system.NativeStart.main(Native Method)
    07-31 08:35:45.582: E/ActivityThread(26448): Activity com.example.com.proto1.Infoactive has leaked ServiceConnection android.speech.tts.TextToSpeech$1@40ccc2c0 that was originally bound here
    07-31 08:35:45.582: E/ActivityThread(26448): android.app.ServiceConnectionLeaked: Activity com.example.com.proto1.Infoactive has leaked ServiceConnection android.speech.tts.TextToSpeech$1@40ccc2c0 that was originally bound here
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:932)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:827)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.ContextImpl.bindService(ContextImpl.java:1109)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:517)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:483)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at com.example.com.proto1.Infoactive.onActivityResult(Infoactive.java:193)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.Activity.dispatchActivityResult(Activity.java:4581)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:2817)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:2864)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.ActivityThread.access$1000(ActivityThread.java:122)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1057)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.os.Looper.loop(Looper.java:132)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at android.app.ActivityThread.main(ActivityThread.java:4126)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at java.lang.reflect.Method.invokeNative(Native Method)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at java.lang.reflect.Method.invoke(Method.java:491)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    07-31 08:35:45.582: E/ActivityThread(26448): 	at dalvik.system.NativeStart.main(Native Method)
    07-31 08:35:45.612: D/dalvikvm(26448): GC_CONCURRENT freed 4098K, 35% free 8188K/12423K, paused 3ms+3ms
    07-31 08:35:56.452: D/CLIPBOARD(26448): Hide Clipboard dialog at Starting input: finished by someone else... !
    07-31 08:36:06.212: D/AndroidRuntime(26448): Shutting down VM
    07-31 08:36:06.212: W/dalvikvm(26448): threadid=1: thread exiting with uncaught exception (group=0x402d0760)
    07-31 08:36:06.212: E/AndroidRuntime(26448): FATAL EXCEPTION: main
    07-31 08:36:06.212: E/AndroidRuntime(26448): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1234, result=-1, data=Intent { (has extras) }} to activity {com.example.com.proto1/com.example.com.proto1.VoiceRecognition}: java.lang.NullPointerException
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:2821)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:2864)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.ActivityThread.access$1000(ActivityThread.java:122)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1057)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.os.Looper.loop(Looper.java:132)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.ActivityThread.main(ActivityThread.java:4126)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at java.lang.reflect.Method.invokeNative(Native Method)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at java.lang.reflect.Method.invoke(Method.java:491)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at dalvik.system.NativeStart.main(Native Method)
    07-31 08:36:06.212: E/AndroidRuntime(26448): Caused by: java.lang.NullPointerException
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at com.example.com.proto1.VoiceRecognition.speakWords(VoiceRecognition.java:193)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at com.example.com.proto1.VoiceRecognition.onActivityResult(VoiceRecognition.java:155)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.Activity.dispatchActivityResult(Activity.java:4581)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:2817)
    07-31 08:36:06.212: E/AndroidRuntime(26448): 	... 11 more

    

        import android.app.Activity;
    
    /**
     * Sample code that invokes the speech recognition intent API.
     */
    public class VoiceRecognition extends Activity implements OnClickListener,
    		OnInitListener {
    
    	public static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
    
    	public ListView mList;
    	public Button speakButton;
    	// TTS object
    	public TextToSpeech myTTS;
    	// status check code
    	public int MY_DATA_CHECK_CODE = 0;
    
    	public void informationmenu() {
    		speakWords("information screen");
    		startActivity(new Intent("android.intent.action.INFOSCREEN"));
    	}
    
    	public void voicemenu() {
    		speakWords("voice recognition menu");
    		startActivity(new Intent("android.intent.action.RECOGNITIONMENU"));
    	}
    
    	public void mainmenu() {
    		speakWords("main menu");
    		startActivity(new Intent("android.intent.action.MENU"));
    	}
    
    	public void voicerecog() {
    		speakWords("speak now");
    		startActivity(new Intent("android.intent.action.SPEAK"));
    	}
    
    	/**
    	 * Called with the activity is first created.
    	 */
    	@Override
    	public void onCreate(Bundle voiceinput) {
    		super.onCreate(voiceinput);
    
    		// Inflate our UI from its XML layout description.
    		setContentView(R.layout.voice_recognition);
    
    		// check for TTS data
    		Intent checkTTSIntent = new Intent();
    		checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    		startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
    
    		// Get display items for later interaction
    
    		voiceinputbuttons();
    
    		// Check to see if a recognition activity is present
    		PackageManager pm = getPackageManager();
    		List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(
    				RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    		if (activities.size() != 0) {
    			speakButton.setOnClickListener(this);
    		} else {
    			speakButton.setEnabled(false);
    			speakButton.setText("Recognizer not present");
    		}
    	}
    
    	// setup TTS
    	public void onInit(int initStatus) {
    
    		// check for successful instantiation
    		if (initStatus == TextToSpeech.SUCCESS) {
    			if (myTTS.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE)
    				myTTS.setLanguage(Locale.US);
    		} else if (initStatus == TextToSpeech.ERROR) {
    			Toast.makeText(this, "Sorry! Text To Speech failed...",
    					Toast.LENGTH_LONG).show();
    		}
    	}
    
    	/**
    	 * Handle the click on the start recognition button.
    	 */
    
    	public void onClick(View v) {
    		startVoiceRecognitionActivity();
    	}
    
    	public void voiceinputbuttons() {
    		speakButton = (Button) findViewById(R.id.btn_speak);
    		mList = (ListView) findViewById(R.id.list);
    	}
    
    	/**
    	 * Fire an intent to start the speech recognition activity.
    	 */
    	public void startVoiceRecognitionActivity() {
    		Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    		intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
    				RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    		intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
    				"Speech recognition demo");
    		startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
    	}
    
    	/**
    	 * Handle the results from the recognition activity.
    	 */
    	@Override
    	public void onActivityResult(int requestCode, int resultCode, Intent data) {
    		if (requestCode == VOICE_RECOGNITION_REQUEST_CODE
    				&& resultCode == RESULT_OK) {
    			// Fill the list view with the strings the recognizer thought it
    			// could have heard
    			ArrayList<String> matches = data
    					.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    			mList.setAdapter(new ArrayAdapter<String>(this,
    					android.R.layout.simple_list_item_1, matches));
    			// matches is the result of voice input. It is a list of what the
    			// user possibly said.
    			// Using an if statement for the keyword you want to use allows the
    			// use of any activity if keywords match
    			// it is possible to set up multiple keywords to use the same
    			// activity so more than one word will allow the user
    			// to use the activity (makes it so the user doesn't have to
    			// memorize words from a list)
    			// to use an activity from the voice input information simply use
    			// the following format;
    			// if (matches.contains("keyword here") { startActivity(new
    			// Intent("name.of.manifest.ACTIVITY")
    
    			if (matches.contains("information || info screen || info || about")) {
    				informationmenu();
    			} else {
    				speakWords("Speak Now");
    				startVoiceRecognitionActivity();
    				if (matches.contains("home || menu || home screen")) {
    					mainmenu();
    				} else {
    					speakWords("Speak Now");
    					startVoiceRecognitionActivity();
    				}
    				if (matches.contains("speak")) {
    					voicerecog();
    				} else {
    					speakWords("Speak Now");
    					startVoiceRecognitionActivity();
    				}
    				if (matches.contains("close || stop || finish")) {
    					finish();
    				} else {
    					speakWords("Speak Now");
    					startVoiceRecognitionActivity();
    				}
    				if (matches
    						.contains("voice || recognition|| voice recognition")) {
    					voicemenu();
    				} else {
    					speakWords("Speak Now");
    					startVoiceRecognitionActivity();
    				}
    
    			}
    		}
    		super.onActivityResult(requestCode, resultCode, data);
    
    	}
    
    	// speak the user text
    	public void speakWords(String speech) {
    
    		// speak straight away
    		myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
    	}
    
    }


            import java.util.Locale;
    

    
    @SuppressWarnings("unused")
    public class mainj extends Activity implements OnInitListener {
    
    	private TextToSpeech myTTS;
    	// status check code
    	private int MY_DATA_CHECK_CODE = 0;
    
    	// setup TTS
    	public void onInit(int initStatus) {
    
    		// check for successful instantiation
    		if (initStatus == TextToSpeech.SUCCESS) {
    			if (myTTS.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE)
    				myTTS.setLanguage(Locale.US);
    		} else if (initStatus == TextToSpeech.ERROR) {
    			Toast.makeText(this, "Sorry! Text To Speech failed...",
    					Toast.LENGTH_LONG).show();
    		}
    	}
    
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.loadscreen);
    		Intent checkTTSIntent = new Intent();
    		checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    		startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
    		Thread logoTimer = new Thread() {
    			public void run() {
    				try {
    					try {
    						sleep(3000);
    						speakWords("main menu loaded");
    					} catch (InterruptedException e) {
    						e.printStackTrace();
    					}
    
    					Intent menuIntent = new Intent("android.intent.action.MENU");
    					startActivity(menuIntent);
    
    				}
    
    				finally {
    					finish();
    				}
    			}
    
    		};
    		logoTimer.start();
    	}
    
    	// speak the user text
    	private void speakWords(String speech) {
    
    		// speak straight away
    		if (myTTS != null) {
    			myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
    		}
    	}
    
    	// act on result of TTS data check
    	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    
    		if (requestCode == MY_DATA_CHECK_CODE) {
    			if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
    				// the user has the necessary data - create the TTS
    				myTTS = new TextToSpeech(this, this);
    			} else {
    				// no data - install it now
    				Intent installTTSIntent = new Intent();
    				installTTSIntent
    						.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
    				startActivity(installTTSIntent);
    			}
    		}
    	}


            import android.app.Activity;
   
    @SuppressWarnings("unused")
    public class menu extends Activity implements TextToSpeech.OnInitListener,
    		OnClickListener {
    
    	// defined
    	TextToSpeech mTts;
    	public static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
    
    	// remember to include a listview on the xml or the voice recognition code
    	// will not work
    	public ListView mList;
    	// TTS object
    	Button speakButton, infoButton, voiceButton, talkButton;
    
    	VoiceRecognition vro = new VoiceRecognition();
    	SpeakingAndroid speak = new SpeakingAndroid();
    
    	// TTS object
    	public TextToSpeech myTTS;
    	// status check code
    	public int MY_DATA_CHECK_CODE = 0;
    
    	@Override
    	protected void onCreate(Bundle aboutmenu) {
    		super.onCreate(aboutmenu);
    		setContentView(R.layout.mainx);
    
    		VoiceRecognition voiceinput = new VoiceRecognition();
    
    		// get a reference to the button element listed in the XML layout
    		speakButton = (Button) findViewById(R.id.btn_speak);
    		infoButton = (Button) findViewById(R.id.aboutbutton);
    		voiceButton = (Button) findViewById(R.id.voicebutton);
    		talkButton = (Button) findViewById(R.id.talk);
    
    		// listen for clicks
    		infoButton.setOnClickListener(this);
    		speakButton.setOnClickListener(this);
    		talkButton.setOnClickListener(this);
    
    		// check for TTS data
    		Intent checkTTSIntent = new Intent();
    		checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    		startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
    
    		// calling method
    		voiceinputbuttons();
    
    		// Check to see if a recognition activity is present
    		// if running on AVD virtual device it will give this message. The mic
    		// required only works on an actual android device//
    		PackageManager pm = getPackageManager();
    		List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(
    				RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    		if (activities.size() != 0) {
    			voiceButton.setOnClickListener(this);
    		} else {
    			voiceButton.setEnabled(false);
    			voiceButton.setText("Recognizer not present");
    		}
    
    	}
    
    	// setup TTS
    	public void onInit(int initStatus) {
    
    		// check for successful instantiation
    
    		// returns a fail statement if speech doesn't work
    		if (initStatus == TextToSpeech.SUCCESS) {
    			if (myTTS.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE)
    				myTTS.setLanguage(Locale.US);
    		} else if (initStatus == TextToSpeech.ERROR) {
    			Toast.makeText(this, "Sorry! Text To Speech failed...",
    					Toast.LENGTH_LONG).show();
    		}
    	}
    
    	// creating method
    	public void voiceinputbuttons() {
    		speakButton = (Button) findViewById(R.id.btn_speak);
    		mList = (ListView) findViewById(R.id.list);
    	}
    
    	// respond to button clicks
    	public void onClick(View v) {
    		switch (v.getId()) {
    
    		// use switch case so each button does a different thing
    		// accurately(similar to an if statement)
    		case R.id.btn_speak:
    			String words1 = speakButton.getText().toString();
    
    			// speakwords(xxxx); is the piece of code that actually calls the
    			// text to speech
    			speakWords(words1);
    			Intent voiceIntent = new Intent(
    					"android.intent.action.RECOGNITIONMENU");
    			startActivity(voiceIntent);
    			break;
    		case R.id.aboutbutton:
    			String words2 = infoButton.getText().toString();
    			speakWords(words2);
    			Intent infoIntent = new Intent("android.intent.action.INFOSCREEN");
    			startActivity(infoIntent);
    			break;
    		case R.id.voicebutton:
    			speakWords("Speak Now");
    			startVoiceRecognitionActivity(); // call for voice recognition
    												// activity
    			break;
    		case R.id.talk:
    			speakWords("This is the main menu.");
    			break;
    		}
    	}
    
    	// speak the user text
    	// setting up the speakWords code
    	public void speakWords(String speech) {
    
    		// speak straight away
    		myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
    	}
    
    	/**
    	 * Fire an intent to start the speech recognition activity.
    	 */
    	public void startVoiceRecognitionActivity() {
    		Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    		intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
    				RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    		intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
    				"Speech recognition demo");
    		startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
    	}
    
    	/**
    	 * Handle the results from the recognition activity.
    	 */
    	@Override
    	public void onActivityResult(int requestCode, int resultCode, Intent data) {
    		if (requestCode == VOICE_RECOGNITION_REQUEST_CODE
    				&& resultCode == RESULT_OK) {
    			// Fill the list view with the strings the recognizer thought it
    			// could have heard
    			ArrayList<String> matches = data
    					.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    			mList.setAdapter(new ArrayAdapter<String>(this,
    					android.R.layout.simple_list_item_1, matches));
    			// matches is the result of voice input. It is a list of what the
    			// user possibly said.
    			// Using an if statement for the keyword you want to use allows the
    			// use of any activity if keywords match
    			// it is possible to set up multiple keywords to use the same
    			// activity so more than one word will allow the user
    			// to use the activity (makes it so the user doesn't have to
    			// memorize words from a list)
    			// to use an activity from the voice input information simply use
    			// the following format;
    			// if (matches.contains("keyword here") { startActivity(new
    			// Intent("name.of.manifest.ACTIVITY")
    
    			if (matches.contains("information")) {
    				vro.informationmenu();
    			}
    			if (matches.contains("info screen")) {
    				vro.informationmenu();
    			}
    			if (matches.contains("info")) {
    				vro.informationmenu();
    			}
    			if (matches.contains("about")) {
    				vro.informationmenu();
    			}
    
    			if (matches.contains("home")) {
    				vro.mainmenu();
    			}
    			if (matches.contains("menu")) {
    				vro.mainmenu();
    			}
    			if (matches.contains("home screen")) {
    				vro.mainmenu();
    			}
    			if (matches.contains("speak")) {
    				vro.voicerecog();
    			}
    			if (matches.contains("close")) {
    				finish();
    			}
    			if (matches.contains("stop")) {
    				finish();
    			}
    			if (matches.contains("finish")) {
    				finish();
    			}
    			if (matches.contains("voice")) {
    				vro.voicemenu();
    			}
    			if (matches.contains("recognition")) {
    				vro.voicemenu();
    			}
    			if (matches.contains("voice recognition")) {
    				vro.voicemenu();
    			}
    
    		}
    
    		// still in the onActivityResult: This is for the text to speech part
    
    		if (requestCode == MY_DATA_CHECK_CODE) {
    			if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
    				// the user has the necessary data - create the TTS
    				myTTS = new TextToSpeech(this, this);
    			} else {
    				// no data - install it now
    				Intent installTTSIntent = new Intent();
    				installTTSIntent
    						.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
    				startActivity(installTTSIntent);
    			}
    		}
    
    		super.onActivityResult(requestCode, resultCode, data);
    
    	}
    
    }



