last day (15 days later) » 

5:33 PM
1
A: Android: Pause and resume a thread within an activity

mmloolooAll of the answers i think have some issues about your running variable because you can not write and read a variable from two different Threads without synchronized block so i post my own answer: public class MonitorObject{ } final MonitorObject mSync = new MonitorObject(); @Override protected ...

 
Check my edit please
Your code doesn't even work. Boolean is not a valid type's argument for the synchronized statement.
 
fix it look again and thanks
and the accepted answer is wrong because it is not thread safe.
 
Elaborate on 'not thread safe' please. I have limited experience with threads but as far as I know, pausing/unpausing/stopping threads with booleans are fine.
 
I've read up a bit on thread safety and you are right, I will add the synchronized block and upvote
Hello
Just a quick question, did you mean to encapsulate the whole method with the MonitorObject class?
 
5:34 PM
hello
no you must encapsulate the boolean
because
one thread that is your UI thread write it
makes it true and false
 
so, public class MonitorObject{
}
public class MonitorObject{ boolean running;
}
 
and the other thread read it
no as you told me we should not use
 
Could you update your answer because in your answer right now MonitorObject is just an empty class
 
primitive in synchornized() parantices
so i create a dummy object and put it in the parantices
in that block i update your boolean
so every thread thats want to access
to your boolean must first get the
permission from synchornized block
thats it
if you read those links you will understand it better
 
Okay. But the MonitorObject class is supposed to be empty?
 
5:39 PM
yes it must be an object any but with some restriction that explained in the synchuornized link
if you do not have any question Good Luck
 
Okay thanks alot for your help. As I said I'm not very experienced with threads and very limited experience in programming overall. Changed the accepted answer to yours
thanks bb
 
Bye
 

last day (15 days later) »