Attachment Link to my previous question: From memory
I will try to be as accurate as possible. I get a response from my web service for a long base64 string. I decode the string and get a huge string containing my data. I de-serialize the string and create an object of my class using the string as shown below.
String decryptedXml = XmlObject.toDecryptedXmlString(gameDetail.getGameData(), app.getSessionEncryptionKey());
Game noviceGame = deserialiseGame(decryptedXml, NoviceGamer.class);
desrialiseGame () is just a method that deserializes the data and creates and returns my game instance. To save this object in several sessions (input / output), I save my entire game (my line, whose de-serialization gave me an instance of Game) in the database.
The next time a user logs in to create an instance of the game, I retrieve a row from my database and try again to de-serialize to get an instance of my game. But when I try to get a row from my database, I get an “OUT OF MEMORY” exception when retrieving a row.
The method called to de-serialize the game is below.
private HashMap<String, Game> games = new HashMap<String, Game>();
public void load(LocalDatabaseHelper localDbHelper) throws Exception
{
synchronized(gameLockObject) {
GameDetailDAO dao = new GameDetailDAO(localDbHelper);
ArrayList<GameDetailEntity> dbGameDetails = dao.getEntities(null, null);
for (GameDetailEntity gameDetail : dbGameDetails) {
String gameLevel = gameDetail.getDetailLevel();
String gameXml = gameDetail.getGameData();
Game game = null;
if(gameLevel.equalsIgnoreCase("Novice")) {
game = Job.deserialiseJob(gameXml, NoviceLevel.class);
}
else if (gameLevel.equalsIgnoreCase("Expert")) {
game = Job.deserialiseJob(gameXml, ExpertLevel.class);
}
game.setGameversion(gameDetail.getGameVersion());
game.setMagicNumber(gameDetail.getMagicNumber());
game.setInactiveUser(gameDetail.getInactiveUser());
game.setStartTime(gameDetail.getStartTime());
game.setFinishTime(gameDetail.getFinishTime());
game.setGameCompletionTime(gameDetail.getGameCompletionTime());
if (!StringUtils.isNullOrEmpty(gameDetail.getGameStatus())) {
game.setGameStatus(GameStatus.valueOf(gameDetail.getGameStatus()));
}
games.put(gameDetail.getGameRef().toLowerCase(Locale.getDefault()), game);
}
}
}
My database transaction is as follows:
@Override
protected GameEntity getEntityFromCursor(Cursor cursor)
{
String gameRef = cursor.getString(cursor.getColumnIndex(GAME_REF));
String detailLevel = cursor.getString(cursor.getColumnIndex(DETAIL_LEVEL));
int gameVersion = cursor.getInt(cursor.getColumnIndex(GAME_VERSION));
String gameData = cursor.getString(cursor.getColumnIndex(GAME_DATA));
String status = cursor.getString(cursor.getColumnIndex(GAME_STATUS));
long longStart = cursor.getLong(cursor.getColumnIndex(VISIT_START_TIME));
Date startTime = longStart == -1 ? null : new Date(longStart);
long longFinish = cursor.getLong(cursor.getColumnIndex(VISIT_END_TIME));
Date finishTime = longFinish == -1 ? null : new Date(longFinish);
long longComplete = cursor.getLong(cursor.getColumnIndex(GAME_COMPLETION_TIME));
Date completionTime = longComplete == -1 ? null : new Date(longComplete);
GameEntity entity = new GameEntity(gameRef, detailLevel, gameVersion, gameData, );
entity.setGameStatus(status);
entity.setStartTime(startTime);
entity.setFinishTime(finishTime);
entity.setGameCompletionTime(completionTime);
return entity;
}
but when I try to get data from the @Line database
String gameData = cursor.getString(cursor.getColumnIndex(GAME_DATA));I go out of memory. According to my conclusion, when I add the largeHeap = true flag in the manifest in the application tag, my application is pretty darn slow. In addition, developers and android states
, - , . , , , .
- , . , SO. .