Thread, Activity and DB

Put your problem here if it does not fit any of the other categories.

Thread, Activity and DB

Postby Malefico » Mon Nov 17, 2008 10:41 am

I have a problem:

i have an activity. It call a thread that access a sqlite db to process many data ( it takes about 5 sec ) ..

if during the thread is runnig i press the back or the home button the application crash.

How can i stop/destroy the thread? i think i have to do this in onPause() method.

thx
Malefico
Developer
Developer
 
Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

Top

Postby MrSnowflake » Mon Nov 17, 2008 11:51 am

The best way is to use Thread.join() (this'll make you activity wait for the thread to finish), because your thread could be writing stuff to the db. But you also should flag something in the Thread, to the Thread knows it's supposed to shutdown (just return from the run() is enough).
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Malefico » Mon Nov 17, 2008 2:20 pm

Thanks! 8)

I think i will use both:
the FLAG to let thread know it must end.. and JOIN to wait the thread ends.
Malefico
Developer
Developer
 
Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 13 guests