Android problem with saving the doc.

瀏覽次數:30 次
跳到第一則未讀訊息

Siddharth Shah

未讀,
2015年1月12日 晚上10:49:152015/1/12
收件者: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

未讀,
2015年1月12日 晚上11:54:412015/1/12
收件者: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

未讀,
2015年1月13日 清晨5:29:462015/1/13
收件者: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

未讀,
2015年1月13日 下午3:19:122015/1/13
收件者: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.


回覆所有人
回覆作者
轉寄
0 則新訊息