Question

I am creating a mail application in Flex mobile. How can I implement an offline cache feature in my Flex mobile application?

I need offline caching for mail which comes in to the user's Inbox, so if the user has no connection, they can read previous/old email messages which were cached when they previously connected.

Is this possible from the Flex side? If so, how? If not, then what is a solution or what could I do for that.

On the server side i am using .net for getting data.

Was it helpful?

Solution

One possible (simple) solution is to use SharedObject:

public void cacheIncomingMail(message:EmailMessage):void {
  var so:SharedObject = SharedObject.getLocal("mobileMail");
  var cachedMessages:Array = so.data.messages;
  //Decide whether to remove anything from the array
  cachedMessages.push(message);
  so.data.messages = cachedMessages;
}

Be aware that this solution can dump a LOT of data into the SharedObject; Adobe's documentation suggests that you use SharedObject for "limited amounts of data"

An alternative is to use the File class:

public void cacheIncomingMail(message:EmailMessage):void {
  var dataFolder:File = File.applicationStorageDirectory;
  var desiredFilename:String = makeFilenameFromEmail(message);
  var mailStorageFile:File = dataFolder.resolvePath(desiredFilename);
  var fileStream:FileStream = new FileStream();
  fileStream.open(file, FileMode.WRITE);
  fileStream.writeUTF(message.toXML());
  fileStream.close();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top