Terminate the application

When the user closes the Good Citizen application, we need to do a bit of cleaning up to make sure the application shuts down properly. When an application receives a NAVIGATOR_EXIT event, the system directs the application to start shutting down. The application then has a certain amount of time (about 500 ms) to save its state and perform any additional cleanup operations. After this time has elapsed, if the application isn't terminated yet, the system terminates it. To perform clean exits, you should avoid cleanup operations that take a long time (such as writing large amounts of data to a file).

In main(), after the application loop has exited due to user action, the first thing to do is stop requesting events from the screen.

screen_stop_events(screen_cxt);

Invoke bbutil_terminate(). This function cleans up the EGL setup by performing tasks such as destroying the EGL surface, context, and libscreen window.

bbutil_terminate();

Shut down the BlackBerry Platform Services library, since we no longer need any BlackBerry Platform Services functions for our application. It's important to remember that after you perform this step, your application shouldn't call any other BlackBerry Platform Services functions.

bps_shutdown();

Destroy the screen context and exit the application.

screen_destroy_context(screen_cxt);
return 0;

That's it! You can now run and play with the Good Citizen application! You can try changing the behaviour of the application to use different colors, change the menu text, or use a different shape for the object.