Show dialog from background thread - problem
In my app while copying files I want to ask user whether he wants to overwrite the file with same name, skip, etc. Here is some code from the thread:
if(target.exists()){
synchronized(this){
while(wait){
try{
popupHandler.sendMessage(popupHandler.obtainMessage(0, target));
wait();
}catch (Exception e){
e.printStackTrace();
}
}
}
}
Here is my handler:
Handler popupHandler = new Handler(){
@Override
public void handleMessage(Message m){
c.showConfirmDialog("The file " + ((File)m.obj).getName() + " exists. What do you want to do?",
"Overwrite", "Skip", "Keep both", Explorer.PASTE_CONFIRM, null);
}
};
After choosing an option from dialog something like that is called:
public void resume(){
synchronized(copyThread){
copyThread.wait = false;
copyThread.notify();
}
}
And here goes the problem. The copyThread on resume() is always null. I can't find what is wrong because t开发者_运维知识库he same scheme with pausing the thread works in my other class. It looks like the thread is dying after sending the message:/ Any ideas? Thanks in advance.
精彩评论