iOS Question Hook for applicationWillTerminate?

JordiCP

Expert
Licensed User
Longtime User
With B4I We have access to nearly all the Application Delegate events (Bckground, Foreground, Active, Inactive..) but I can't see how to add some needed code to applicationWillTerminate.

My app does several things in background and needs some stuff to be done in case it is terminated.

How can I get this event?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Full example:
B4X:
Private Sub Application_Start (Nav As NavigationController)
    'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
    Log(File.Exists(File.DirDocuments, "test")) 'it will be true after the terminate event ran
End Sub

Private Sub Application_Terminate
    File.WriteString(File.DirDocuments, "test", "test")
    Log("you will not see this.")
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
   
End Sub

Private Sub Application_Background
   
End Sub

#if OBJC
@end
@implementation B4IAppDelegate (terminate)
- (void)applicationWillTerminate:(UIApplication *)application {
    B4I* bi = [b4i_main new].bi;
[bi raiseEvent:nil event:@"application_terminate" params:nil];
}
#End If

However the terminate event is not useful as there are many cases where it will not be raised. Normally applications should "clean" whatever they need in the background event.
 
Upvote 0
Top