Skip to content

Lifecycle Hooks

Xed-Editor extensions can react to both the extension's own lifecycle and the standard Android activity lifecycle of the host application.

Extension vs Activity Lifecycle

There are two different layers you must understand:

  • Extension lifecycle → controlled by Xed-Editor, with each extension having its own lifecycle
  • Android activity lifecycle → forwarded from the host app (Activity callbacks)

Available Lifecycle Methods

All lifecycle methods are defined in your extension's main entry class, which inherits from ExtensionAPI. Ignore the annotations and the context parameter for now. This will be covered on the next page.

kotlin
@Keep
@Suppress("unused")
class Main(context: ExtensionContext) : ExtensionAPI(context) {
    override fun onLoad() {} 
    override fun onDispose() {}
  
    override fun onInstalled() {}
    override fun onUninstalled() {}
    override fun onUpdated() {}

    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}
    override fun onActivityStarted(activity: Activity) {}
    override fun onActivityResumed(activity: Activity) {}
    override fun onActivityPaused(activity: Activity) {}
    override fun onActivityStopped(activity: Activity) {}
    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
    override fun onActivityDestroyed(activity: Activity) {}
}

Only the onLoad methods must be overridden in your entry class. The other lifecycle methods default to empty implementations and only need to be overridden if you want to provide custom behavior.

Lifecycle Reference Table

Extension Lifecycle Hooks

MethodCalled WhenRecommended Use in Extensions
onLoadExtension is loaded into memoryPrimary initialization: Register commands/listeners, load persistent state, initialize services, and prepare extension resources.
onDisposeExtension is unloaded from memoryRelease resources created by the extension, stop services, unregister commands/listeners, and perform general cleanup.
onInstalledExtension is installed for the first timeInitial setup tasks such as creating default configuration, preparing files, or validating prerequisites.
onUninstalledExtension is removed from the applicationFinal cleanup such as deleting extension-specific files, removing cached data, or unregistering persistent resources.
onUpdatedExtension is updated to a newer versionHandle migration tasks between extension versions, or show changelog dialog.

NOTE

onUpdated() is invoked before the new extension version is loaded, meaning it runs on the old instance.

Android Activity Lifecycle Hooks

MethodCalled When
onActivityCreatedAn activity is created
onActivityStartedAn activity becomes visible
onActivityResumedAn activity enters the foreground
onActivityPausedAn activity is paused
onActivityStoppedAn activity is no longer visible
onActivitySaveInstanceStateAn activity state is saved
onActivityDestroyedAn activity is destroyed

onLoad() vs onActivityCreated()

onLoad() is the primary entry point for extensions and should be used for all initialization such as registering commands, loading state, or starting services. It is guaranteed to run when the extension is loaded, independent of the current UI state.

In contrast, onActivityCreated() is tied to the Android activity lifecycle and may already have been triggered before the extension is loaded. Because of this timing, it is not reliable for initialization and should only be used when reacting to UI creation events that happen after the extension is active (for example when editor or terminal screens are opened).