Reputation: 81
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.
Upvotes: 0
Views: 57
Reputation: 81
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. :)
Upvotes: 0
Reputation: 81
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.
Upvotes: 1