2010-07-02 29 views
0

在通過iOS-4多任務處理進行快速上下文切換時,我對保存應用程序的最後狀態存在疑問。快速上下文切換時保存當前狀態 - iOS4

應用程序是否必須手動將最後一個狀態保存在「 - (void)applicationDidEnterBackground:(UIApplication *)application」中?或者iOS-4會照顧它?

在它提到的視頻如下:提前

-(void)applicationDidEnterBackground:(UIApplication *)application { 
    // save app state 
    [self saveState]; 

    // reduce memory usages 
    .... 

    // prepare UI 
    .... 

    // close listening sockets 
    .... 
} 

感謝,

蘇尼爾

回答

0

一旦你的應用已經進入後臺,也不能保證它永遠不會再回到前臺。它可能會在任何時候終止,而無需通知任何形式。因此,進入後臺時,您想要保存狀態或有可能丟失狀態。

引述蘋果(來源:http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html),

移動到後臺之前保存應用程序的狀態。在內存不足的情況下,後臺應用程序將從內存中清除以釋放空間。暫停的應用程序首先被清除,在清除之前不會通知應用程序。因此,在移至背景之前,如果需要,應用程序應始終保存足夠的狀態信息以在稍後重新構建。將應用程序恢復到以前的狀態也爲用戶提供了一致性,當用戶重新啓動時,他們會短暫地看到應用程序主窗口的快照。

0

不要應用已經手動保存在最後的狀態 「 - (空)applicationDidEnterBackground:(UIApplication的*)應用程序」?或者iOS-4會照顧它?

是的,如果你希望你的應用程序,以恢復它的被殺害後,您需要手動保存狀態在這裏。

0

您應該在您的應用程序委託中使用這兩種方法來在進入後臺/終止之前保存當前狀態。

- (void)applicationWillResignActive:(UIApplication *)application { 

    /* 
    Sent when the application is about to move from active to inactive state. 
    This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) 
    or when the user quits the application and it begins the transition to the background state. 
    Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. 
    Games should use this method to pause the game. 
    */ 
} 
    - (void)applicationWillTerminate:(UIApplication *)application { 

    /* 
    Called when the application is about to terminate. 
    See also applicationDidEnterBackground:. 
    */ 
}