Android problem with saving the doc.

30 views
Skip to first unread message

Siddharth Shah

unread,
Jan 12, 2015, 10:49:15 PM1/12/15
to pdfne...@googlegroups.com
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.

Ryan

unread,
Jan 12, 2015, 11:54:41 PM1/12/15
to pdfne...@googlegroups.com
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.

Siddharth Shah

unread,
Jan 13, 2015, 5:29:46 AM1/13/15
to pdfne...@googlegroups.com
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.

Ryan

unread,
Jan 13, 2015, 3:19:12 PM1/13/15
to pdfne...@googlegroups.com
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.


Reply all
Reply to author
Forward
0 new messages