I have an activity that may have threads running when the user presses back and finish()es the activity. What happens to those threads at that point? Will they all attempt to complete unless I interrupt them in onDestroy()?
For example, is the below code unsafe, because my views and cursor may be destroyed if the activity finishes before the thread?
The reason I ask is that I have occasional crashes when finishing activities that I haven't successfully debugged yet, because they happen rarely and never while I've been in debug mode. I have since started checking if my view objects are null before doing anything to them in runOnUIThread(). Not sure if that's the cleanest solution, or if that is the problem at all.
new Thread()(
public void run(){
crunchOnSomethingForAwhile(mCursor);
MyActivity.this.runOnUIThread(new Runnable(){
public void run(){
mTextView.setText("thread complete");
mCursor.close();
}
}
}
).start();