我在桌面空氣應用程序中做了什麼; 我想這也可以在移動應用程序工作。
確保您有寫權限; 打開yourproject-app.mxml向下滾動到文檔的末尾。在該部分中,取消對以下權限的註釋:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
現在您可以創建文件,例如sqlite數據庫。
在applicationcomplete調用函數checkFirstRun:
// functions to check if the application is run for the first time (also after updates)
// so important structural changes can be made here.
public var file:File;
public var currentVersion:Number;
private function checkFirstRun():void
{
//get the current application version.
currentVersion=getApplicationVersion();
//get versionfile
file = File.applicationStorageDirectory;
file= file.resolvePath("Preferences/version.txt");
if(file.exists)
{
checkVersion();
}
else
{
firstRun(); // create the version file.
}
}
public function getApplicationVersion():Number
{
var appXML:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:Namespace = appXML.namespace();
var versionnumber:Number =Number(appXML.ns::versionNumber);
return versionnumber;
}
private function checkVersion():void
{
var stream:FileStream= new FileStream();
stream.open(file,FileMode.READ);
var prevVersion:String = stream.readUTFBytes(stream.bytesAvailable);
stream.close();
if(Number(prevVersion)<currentVersion)
{
// if the versionnumber inside the file is older than the current version we go and run important code.
// like alternating the structure of tables inside the sqlite database file.
runImportantCode();
//after running the important code, we set the version to the currentversion.
saveFile(currentVersion);
}
}
private function firstRun():void
{
// at the first time, we set the file version to 0, so the important code will be executed.
var firstVersion:Number=0;
saveFile(firstVersion);
// we also run the checkversion so important code is run right after installing an update
//(and the version file doesn't exist before the update).
checkFirstRun();
}
private function saveFile(currentVersion:Number):void
{
var stream:FileStream=new FileStream();
stream.open(file,FileMode.WRITE);
stream.writeUTFBytes(String(currentVersion));
stream.close();
}
private function runImportantCode():void
{
// here goes important code.
// make sure you check if the important change previously has been made or not, because this code is run after each update.
}
希望這有助於。 Greets,J.
謝謝,我愛最簡單的方法。是將一個ContextData對象序列化到文件系統並在啓動時恢復它。如果它是空的,那麼這是第一次? – 2012-04-28 18:17:41
請側面提問:P:彈出窗口不包含背後的主要視圖。它看起來像一團糟!你能否告訴我顯示這個用戶協議的最簡單的方法。注意:我已經有2個標籤系統。一個用於登錄/註冊,另一個用於主應用程序.. – 2012-04-28 18:20:22
是的,共享對象本質上是一個用於少量數據的本地數據存儲。類似於瀏覽器cookie。查看共享對象上的文檔:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html。我無法用彈出窗口評論您的應用程序的可視化顯示,而不會看到屏幕截圖。 – JeffryHouser 2012-04-28 19:24:03