0
我使用下拉框同步API的Android平臺,下面的場景是發生:onFileChange(DbxFile文件)多次調用(exaclty 8倍)時,文件更改
- 用戶A已經打開某些文件(說A.xls)。
- 雖然userA的文件仍處於打開狀態,但userB對同一文件進行了一些更改並將文件推送到Dropbox上。
- 現在userA獲得onFileChange(DbxFile文件)的回調。每次更新時,此方法每次只准確調用8次。
我需要確認的是多個回調更新是SyncAPI的一個功能。
如果它是一個功能,有沒有什麼辦法可以禁用它,以獲得每次更新只有1個回調。
如果它不是一個功能,你能建議任何可能性爲什麼發生這種情況。
從我身邊,我檢查了監聽器只註冊一次,實現監聽器的類是單例。
我希望以下代碼和日誌可能會爲您提供更多信息。
@Override
public void onFileChange(DbxFile oldFile) {
try {
Log.d(tag, "onFileChange count = " + count);
if (count % 8 == 0) {
Date oldFileDate = oldFile.getInfo().modifiedTime;
Log.d(tag, "current file modification time = " + oldFileDate + "\t file status = " + getStatus(oldFile));
DbxPath mpath = oldFile.getPath();
Log.d(tag, "Kicking thread");
Runnable newFileStatusCheckRunnable = new CheckNewFileUpdateTask(context.getDbxFs(), mpath, oldFile);
Thread newFileStatusCheckThread = new Thread(newFileStatusCheckRunnable);
newFileStatusCheckThread.start();
}
Log.d(tag, "Incrmenting counter");
count++;
} catch (DbxException e) {
e.printStackTrace();
}
}
日誌(僅日誌的相關部分加入)
01-11 18:22:12.515: D/FileChangeListener(6127): onFileChange count = 0
01-11 18:22:12.515: D/FileChangeListener(6127): current file modification time = Sat Jan 11 17:43:17 GMT+05:30 2014 file status = isLatestDOWNLOAD
01-11 18:22:12.515: D/FileChangeListener(6127): Kicking thread
01-11 18:22:12.525: D/FileChangeListener(6127): Incrmenting counter
01-11 18:22:12.525: D/FileChangeListener(6127): trying first time
01-11 18:22:12.525: D/FileChangeListener(6127): checking, if downloding then wait
01-11 18:22:14.908: D/FileChangeListener(6127): onFileChange count = 1
01-11 18:22:14.908: D/FileChangeListener(6127): Incrmenting counter
01-11 18:22:14.908: D/FileChangeListener(6127): onFileChange count = 2
01-11 18:22:14.908: D/FileChangeListener(6127): Incrmenting counter
01-11 18:22:15.308: D/FileChangeListener(6127): onFileChange count = 3
01-11 18:22:15.308: D/FileChangeListener(6127): Incrmenting counter
01-11 18:22:15.308: D/FileChangeListener(6127): onFileChange count = 4
01-11 18:22:15.308: D/FileChangeListener(6127): Incrmenting counter
01-11 18:22:15.688: D/FileChangeListener(6127): onFileChange count = 5
01-11 18:22:15.688: D/FileChangeListener(6127): Incrmenting counter
01-11 18:22:15.688: D/FileChangeListener(6127): onFileChange count = 6
01-11 18:22:15.688: D/FileChangeListener(6127): Incrmenting counter
01-11 18:22:15.719: D/FileChangeListener(6127): onFileChange count = 7
01-11 18:22:15.719: D/FileChangeListener(6127): Incrmenting counter
01-11 18:22:15.719: D/FileChangeListener(6127): wait over
01-11 18:22:15.719: E/libDropboxSync.so(ERR)(6127): DROPBOX_ERROR_ALREADYOPEN: file.cpp:246: p(/p3.xls) already open (0)
01-11 18:22:15.729: D/FileChangeListener(6127): closing file
01-11 18:22:15.729: D/FileChangeListener(6127): Re-trying to open
01-11 18:22:15.759: D/FileChangeListener(6127): New file time: Sat Jan 11 18:23:08 GMT+05:30 2014
01-11 18:22:15.759: D/gaurav(6127): UtilityBillAppActivity onNotice
我跟進在論壇上你的線程:https://forums.dropbox.com/topic.php?id=110552#post-588124 – Greg
@格雷格您的建議幫了我,但我仍然可以當場兩個回調給我狀態'isCached,isLatest,NONE'。其餘6個回調函數正確地表明該文件沒有被「緩存」,並且它是「isLatest,DOWNLOAD」。 – guptakvgaurav
儘管@Greg提供的鏈接對我有很大的幫助,但我只嘗試瞭解該問題的鏈接,所以仍然回答我自己的問題,希望它也能幫助其他人。所有功勞都歸Greg所指,指向正確的位置。 – guptakvgaurav