I have a working audio input app that uses the AudioRecord class for
low-level PCM continuous audio processing.  The audio stream is read
and analyzed by a separate thread which repeatedly calls
audioRecord.read to process the microphone audio one block at a time.
Currently I create and start up this thread in my main activity's
onResume() and tear it all down in onPause().  However this has led to
a nuisance if the device is rotated during certain critical periods
where I really need to analyze uninterrupted audio.  What I would like
to do is restructure my app so that the audio thread continues to live
and operate through an onPause() and onResume() cycle.  That means my
linkage to my main activity is going to be quite a bit different.
Currently I have instance variables to hold a pointer to the thread
object and to host the runables that are posted when certain points in
the analysis thread are reached.  What is the best practice for
accomplishing this with a thread that can live beyond the activity's
onPause()?

Should I just use static variables to hold the pointer to the thread?
What about app shutdown?  If I have a thread that continues to live
after an onPause(), which is the latest method I can count on being
called in the event of an app shutdown, then how does that thread ever
get killed when the OS wants to kill my app?  Will that statically-
created thread cause the system to hang?  Whenever I use threads (in
Windows and iPhone, for instance) I have always taken responsibility
for shutting down any thread that I create.  But in Android, the
calling of onDestroy() is not guaranteed in the activity lifetime.
Only onPause() is guaranteed.

My app has been working great with the audio thread lifetime being
tied to the lifetime of my main activity, but now that I am
considering severing that tie, I am not so sure what will happen to
that thread.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to