2014-10-30 41 views
0

链接我的Dropbox帐户后,我尝试收集数据存储名称并将其存储在本地数据库中。当我调试我的应用程序时,一切正常,我也可以在数据存储区中找到所有名称。但是当我在没有调试的情况下运行应用程序时,我的数据库似乎为空Android上的Dropbox - listDatastores不同步

我觉得有一个同步问题,有人可以给我线索?我还没有找到解决我的问题的解决方案。

谢谢,如果你能帮助我!

这是有问题的代码部分:

private void gatherData(){ 

     db = new SQliteHelper(this) ; 
     Set<DbxDatastoreInfo> datastorePresent = null ; 



     try { 
      datastorePresent = mDatastoreManager.listDatastores(); 
     } catch (DbxException e1) { 
      e1.printStackTrace(); 
     } 

     Iterator<DbxDatastoreInfo> datastoreLoop = datastorePresent.iterator() ; 
     while (datastoreLoop.hasNext()){ 

      TitleList tit = new TitleList(datastoreLoop.next().id) ; 
      tit.setConnectDropbox(); 
      db.addLists(tit); 

     } 

     mDatastoreManager.shutDown(); 

      Intent returnIntent = new Intent(); 
      boolean syncOK = true ; 
      returnIntent.putExtra("result", syncOK) ; 
      setResult(RESULT_OK, returnIntent); 
      finish(); 


    } 
+0

这可能是相同或相似的:http://stackoverflow.com/questions/23664650/dropbox-datastore-listdatastores-on-ios总之,你可能是在提醒listDatastores在SDK知道数据存储之前,所以在你的DBDatastoreManager上使用一个监听器。 – Greg 2014-10-30 17:35:04

+0

@Greg谢谢你的帮助!的确,我曾看过这篇文章,但我不知道如何解决Android上的听众。你能举个例子吗? – KevHV 2014-10-30 17:44:43

+0

这里的教程展示了如何将侦听器添加到DbxDatastoreManager:https://www.dropbox.com/developers/datastore/tutorial/android#listeners – Greg 2014-10-30 18:04:48

回答

0

由于@格雷格告诉我关于Dropbox的网站上有一个tutorial显示的侦听器。因为它可能对其他人有用,下面你会发现我终于使用的代码。请注意,您的类已经实现了接口DbxDatastoreManager.ListListener以使此代码可以运行。

代码:

private void gatherData(){ 

     /** 
     * Open the local database 
     * Set a listener on the datastore manager to know when data are synced 
     * 
     */ 
     db = new SQliteHelper(this) ; 
     mDatastoreManager.addListListener(this); 

    } 


    /** 
    * 
    * "onDatastoreListChange" is launched once the listener detects datastore is synced, 
    * Then all datastore names on dropbox server are stored inside of the local database device 
    * 
    * @param arg0 
    */ 
    @Override 
    public void onDatastoreListChange(DbxDatastoreManager arg0) { 

     // TODO Auto-generated method stub 
     Set<DbxDatastoreInfo> datastorePresent = null ; 
     try { 
      datastorePresent = mDatastoreManager.listDatastores(); 
     } catch (DbxException e1) { 
      e1.printStackTrace(); 
     } 


     Iterator<DbxDatastoreInfo> datastoreLoop = datastorePresent.iterator() ; 
     while (datastoreLoop.hasNext()){ 

      TitleList tit = new TitleList(datastoreLoop.next().id) ; 
      tit.setConnectDropbox(); 
      db.addLists(tit); 

     } 

      Intent returnIntent = new Intent(); 
      boolean syncOK = true ; 
      returnIntent.putExtra("result", syncOK) ; 
      setResult(RESULT_OK, returnIntent); 
      finish(); 

    }