0
問題摘要:我正在使用後臺方法下載一堆圖像,然後保存圖像以便稍後訪問它們。我的問題是我需要一種方法將每個保存的圖像與我在調用背景方法之前已經確定的字符串相關聯。使用getter和setter將不起作用,因爲在調用每個回調方法之前,字符串可能會更改。繼承getDataInBackgroundMethod的唯一方法是什麼?希望他們是一個更簡單的方法:)實際的代碼工作正常,除了傳入變量。將字符串傳遞到後臺方法
//.... Continued from previous code....
//Iterate through the items of an array that has previously been returned
Word wordObject = (Word) itr.next();
//Get the title to store the picture under in local database.
String stringIwouldLikeToPassIn = wordObject.getTitle();
//Parse file is the object responsible for holding the pictures
ParseFile file = wordObject.getParseFile("Pics");
file.getDataInBackground(new GetDataCallback() {
//Get the actual data for the pictures and then store them in
//local memory in byte form.
public void done(byte[] data, ParseException e) {
if (e == null) {
try {
//*** TO DO: I want to have the tempString be passed in so that
//*** I can save the file with the name of the object that was originally called
---> String stringFromCallBack = stringIwouldLikeToPassIn <---------
//This doesn't work as you can't pass an extra paramater into the call back...
FileOutputStream fos = context.openFileOutput(stringFromBeforeCallBack, Context.MODE_PRIVATE);
fos.write(data);
fos.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} else {
// something went wrong
}
}
});
//Pin each word in the background so we can use the objects
wordObject.pinInBackground(null);
//Add each question round to the local relations
relation.add(wordObject);
//Write each word object to title
Log.d(DEBUG, wordObject.getTitle());
}
//After adding the relative array of question objects then we save
user.pinInBackground(null);
user.saveEventually();
}
});
// }
}