2015-09-22 123 views
-1

檢索到的數據存儲在本地數據庫中,但在嘗試從本地數據庫中獲取關係時,我得到空列表,表明關係數據未固定到本地數據庫。如何在本地數據存儲中解析關係數據?

public void retrieveThreadListStoreInDB() 
{ 
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Threads"); 
    query.include("postedBy"); 
    query.findInBackground(new FindCallback<ParseObject>() { 
     @Override 
     public void done(List<ParseObject> list, ParseException e) { 
      if(e == null) 
      { 
       // Query is successful now lets load data from parse 
       ParseObject.pinAllInBackground((List<ParseObject>) list, new SaveCallback() { 
        @Override 
        public void done(ParseException e) { 
         if(e == null) 
         { 
          if(!isFinishing()) 
          { 
           // TODO : Notify to refresh data 
          } 
         } 
         else 
         { 
          Log.d("DEBUG","ERROR PINNING DATA WITH EXCEPTION : "+e); 
         } 
        } 
       }); 

      } 
     } 
    }); 

那麼應該怎麼針「關係」的數據到本地數據庫??? 什麼是閱讀關係評論的最佳方式。我應該將它們存儲在本地數據存儲中還是將數據放在背景中?

回答

-1

請確保您enableLocalDatastore商店應用程序類Parse.enableLocalDatastore(getApplicationContext());

解析本地數據存儲不會緩存策略工作。我們可以訪問如下的關係數據:

private void getParseData() { 
    if (parseObjectId != null) { 
     mApp.show_PDialog(context, "Loading.."); 
     ParseQuery<ParseObject> parseQuery = new ParseQuery<>("Profile"); 
     parseQuery.getInBackground(parseObjectId, new GetCallback<ParseObject>() { 
      @Override 
      public void done(ParseObject parseObject, ParseException e) { 
       if (e == null) { 
        try { 
         newName = parseObject.getString("name"); 
         newGender = parseObject.getString("gender"); 
         newDOB.setTime(parseObject.getDate("dob")); 
         newTOB.setTime(parseObject.getDate("tob")); 
         newCurrentLocation = parseObject.getParseObject("currentLocation"); 
         newPOB = parseObject.getParseObject("placeOfBirth"); 

         if (newName != null) { 
          displayName.setText(newName); 
         } 
         if (newGender != null) { 
          gender.setText(newGender); 
         } 
         if (newDOB != null) { 
          DateFormat df = new SimpleDateFormat("MMM dd, yyyy", Locale.getDefault()); 
          df.setTimeZone(TimeZone.getTimeZone("UTC")); 
          String subdateStr = df.format(newDOB.getTime()); 
          datePicker.setText(subdateStr); 
         } 
         if (newTOB != null) { 
          DateFormat df = new SimpleDateFormat("hh:mm a", Locale.getDefault()); 
          df.setTimeZone(TimeZone.getTimeZone("UTC")); 
          String subdateStr = df.format(newTOB.getTime()); 
          timepicker.setText(subdateStr); 
         } 
         if (newPOB != null) { 
          placeOfBirth.setText(newPOB.fetchIfNeeded().getString("name") 
            + ", " + newPOB.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name") + ", " + newPOB.getParseObject("Parent").fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name")); 
         } 
         if (newCurrentLocation != null) { 
          currentLocation.setText(newCurrentLocation.fetchIfNeeded().getString("name") 
            + ", " + newCurrentLocation.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name") + ", " + newCurrentLocation.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name")); 
         } 
        } catch (ParseException e1) { 
         e1.printStackTrace(); 
        } 
       } else { 
        e.printStackTrace(); 
       } 
       mApp.dialog.dismiss(); 
      } 
     }); 
    } else { 
     getActivity().finish(); 
    } 
} 
+0

我的本地數據存儲已啓用我試圖將「關係」解析到本地數據存儲?以上是相關的嗎? –

+0

請參閱代碼有方法** fetchIfNeeded()**從指針對象獲取數據首先創建並保存關係對象,然後在您當前的表中獲取其對象ID –

+0

你能解釋清楚一點你在做什麼?或在代碼中寫評論?我們可以將此討論移至聊天嗎? –