The AppletEvent.uninstall Method

When an applet needs to perform some important actions prior to deletion, it might implement the uninstall method of the AppletEvent interface. An applet might find it useful to implement this method for the following types of functions:

  • Release resources such as shared keys and static objects

  • Backup data into another applet's space

  • Notify other dependent applets

Calling uninstall does not guarantee that the applet will be deleted. The applet might not be deleted after the completion of the uninstall method in some of these cases:

  • Other applets or packages are still dependent on this applet.

  • Another applet that needs to be deleted simultaneously cannot currently be deleted.

  • The package that needs to be deleted simultaneously cannot currently be deleted.

  • A tear occurs before the deletion elements are processed.

To ensure that the applets are deleted, implement the uninstall method defensively. Write your applet with these guidelines in mind:

  • The applet continues to function consistently and securely if deletion fails.

  • The applet can withstand a possible tear during the execution.

  • The uninstall method can be called again if deletion is reattempted.

The following example shows such an implementation:

public class TestApp1 extends Applet implements AppletEvent{
        // field set to true after uninstall
        private boolean disableApp = false;
        ...
        public void uninstall(){
                if (!disableApp){
                        JCSystem.beginTransaction();  //to protect against tear
                        disableApp = true;            //mark as uninstalled
                        TestApp2SIO.removeDependency();
                        JCSystem.commitTransaction();
                }
        }
        public boolean select(boolean appInstAlreadyActive) {
                // refuse selection if in uninstalled state
                if (disableApp) return false;
                return true;
        }
        ...
}