Android problem with saving the doc.

I am trying to save the document after annotating it

final Object saveDocumentLock = new Object();

synchronized (saveDocumentLock) {

if (mPDFDoc != null) {
boolean locked = false;
try {
// When trying to execute the following if condition, it always returns false
if (mPDFDoc.tryLock()) {
locked = true;

if (mPDFDoc.isModified()) {
if (mCurrentFile.canWrite()) {

if (mCurrentFile.getAbsolutePath().equalsIgnoreCase(getTempDraftPathWithFile(fileName))) {
Log.v("", “:::::@ save on tempfile”);

mPDFDoc.save(mCurrentFile.getAbsolutePath(), SDFDoc.e_incremental, null);
} else {
Log.v("", “:::::@ create tempfile”);
mPDFDoc.save(getTempDraftPathWithFile(fileName), SDFDoc.e_incremental, null);

}

}
}
}
} catch (PDFNetException e) {
} finally {
try {
if (locked) {
mPDFDoc.unlock();
locked = false;
}
} catch (PDFNetException e) {
}
}
}
}
I am stuck!
Please respond ASAP.

For PDFDoc.tryLock to return false, there must be another thread operating on the doc.

If you did not trigger work on another thread yourself, then you must be using PDFViewCtrl class? PDFViewCtrl needs read locks for rendering, text search, etc.

Yeah I am using PDFViewControl class and yeah it takes the lock. What are the safest ways to handle the locks. I went through the documentation and also with the another thread that explains the lock usage.
But still I am not getting it. Please point me to some good resources/examples.

What method you call, depends on what you want to do.

Based on your code, and comments, it looks like you want to save the file immediately after the user saves an annotation.

Looking at the AnnotEdit.java file that comes with the android SDK, its calling PDFViewCtrl.docLock(true), which is blocking the UI until the lock is acquired.

Assuming you did not acquire a lock on any other thread, this will get the clock very quickly, too fast for the user to notice, as PDFViewCtrl shuts down background threads.