0

I developed an app a little over 2 years ago, where I call the function...

startActivityForResult(intent);

to get microphone input. The program doesn't read past that line of code until I say something into the mic. If I say nothing, then I have the option to tap the mic button and say something. Then, the function onActivityResult() gets called after I finally say something into the mic.

Eventually, my phone updated its operating system, and I noticed that onActivityResult() no longer gets called after I say something into the microphone. Not only that. but since I also have startActivityForResult(intent) used inside a threaded loop, that function repeatedly gets called WHILE it is waiting for me to say something into the mic, not allowing me enough time for me to say anything into the mic (whereas the old operating system waited for me to say something into the mic before continuing onto the function onActivityForResult() to get the results). How would I fix this problem?

Thank you.

  • I think it could be a couple of different things, I'd say we'd need to look at the code to figure it out, one thing I'm thinking is that the app maybe doesn't have the right permissions https://stackoverflow.com/questions/36270253/request-permission-for-microphone-on-android-m – Evin1_ Jul 14 '22 at 01:20
  • How would I send you the code? My app used to work (with all the permissions) until my Android updated its software. Would I need to add new permissions? I am using about 16 different associated .java files to troubleshoot from, but I can send you the MainActivity.java file (which contains 2 threaded loops... 1 that gets the microphone input and another that does text to speech, which has SIRI speak). The main program determines which threaded loop executes. After SIRI is done speaking or the microphone gets input, the 2 threads alternate (or used to properly on the old operating system). – Michael Lowe Jul 14 '22 at 19:23
  • Is there a way to attach my MainActivity.java file or the 16 .java files that my app uses? – Michael Lowe Jul 15 '22 at 14:16
  • I think I am one step closer to solving the problem but still need assistance... as I mentioned, with the old operating system, the microphone waited for ANY input before calling the function onActivityResult(), but since the microphone is inside a timer (with the NEW operating system), the startActivityForResult() function gets called repeatedly, instead of waiting for ANY input before calling onActivityResult(). I put an endless while loop right after startActivityForResult(), and onActivityResult() calls, but I can only use the microphone 1 time because of the endless while loop. – Michael Lowe Jul 15 '22 at 15:18
  • Another words, (with the OLD operating system), startActivityForResult() doesn't allow the 'program flow' of my app to continue past that line of code UNTIL the microphone widget gets input (right after the microphone widget opens, gets input and then closes), where the NEW operating system has the program flow of my app continue past startActivityForResult() WHILE the microphone widget is opened, which is why the timer repeatedly calls startActivityForResult() over and over again, instead of just waiting until the widget gets input and then closes. That is the main problem. – Michael Lowe Jul 15 '22 at 15:39

2 Answers2

1

I believe I was able to resolve the reason why my app was behaving differently (after my Android operating system updated itself)... with the OLD operating system, after startActivityForResult() gets called (with a 'microphone' intent to get microphone input), the microphone widget would open up and the 'program flow' of my app would 'pause' UNTIL microphone input is retrieved from the widget. Then, the program flow of my app would continue after onActivityResult() gets called, whereas the NEW operating system allows the 'program flow' of my app to continue past startActivityForResult() WHILE the microphone widget is opened, thus causing my timer to call startActivityForResult() repeatedly, instead of waiting until the widget (which is a separate program) get input, and then close. If there is a way to code the program flow of my app to 'pause itself' WHILE the microphone widget is open (like the OLD way), please let me know. Thank you.

0

I solved the problem...

When my Android updated its operating system (thus causing the microphone widget to NO LONGER 'pause' my app's program flow until it got microphone input, like it USED TO with the OLD operating system), I had to add an extra private boolean member variable to my MainActivity class (called 'isGetting'). Before the function startActivityForResult() gets called, isGetting gets set to true, and IF isGetting is true, the timer that calls startActivityForResult() skips past that line of code until isGetting is false. Then, when the microphone widget gets input and closes (without the timer calling startActivityForResult() repeatedly, or, as long as 'isGetting' is false), onActivityResult() gets called. Inside onActivityResult(), I added...

isGetting = false;

so that startActivityForResult() can get called once again in my timer after onActivityResult() executes and performs the 'instructions' on what to do WITH the results, and that fixed the problem. :)