I have destroyed my activity by calling finish().But the thread in the activity is still running after destroying the activity and it causes application crash..
How can I handle this?Why the thread runs after destroying the activity?
Please provide some help?
class DBThread extends Thread {
@Override
public void run() {
while (finish) {
Cursor cursor = null;
Cursor mCursor = lrDB.selectUserDetails(mUser_Id);
if (mCursor.getCount() > 0) {
mCursor.moveToNext();
String Name = mCursor .getString(0);
String userName = mCursor .getInt(1);
String password = mCursor .getString(3);
}
mCursor.close();
}
}
}
First correct your thread:
Secondly to close thread gracefuly do something like that in activity:
Note that Thread.destroy() is deprecated and will not work.