I had to declare a static handler because of some Java nonsense with leaks.
static class ParsingCompleteHandler extends Handler {
private final WeakReference<BackupActivity> mTargetActivity;
ParsingCompleteHandler(BackupActivity targetActivity) {
mTargetActivity = new WeakReference<BackupActivity>(targetActivity);
}
@Override
public void handleMessage(Message msg) {
BackupActivity targetActivity = mTargetActivity.get();
targetActivity.updateDialog();
}
};
Elsewhere in the code (inside a runnable) I was trying to sendEmptyMessage() to this handler
Runnable runnable = new Runnable() {
@Override
public void run() {
lastBackupDataObject = getBackupDataObjectFromFile(file);
parsingCompleteHandler.sendEmptyMessage(0);
}
};
Thread parsingThread = new Thread(runnable);
parsingThread.start();
but since the sendEmptyMessage()
method is not static (and the handler now is), obviously I can't do it. And I need to send a message to the handler because that's what it's there for. How do I do it?