setContext

open fun setContext(@NonNull context: Context)

Deprecated

Don't rely on the global context. Pass the context you need explicitly.

Set the current context.

The context should never be null after the library was loaded.

This should be the activity that is currently running, or if there is none, the last one that was. It should also be set in the first activity's onCreate.

When last of your activities is destroyed, it is advised to set the context to the application (non-activity) context to release resources:

AndroidUtil.setContext(AndroidUtil.getApplicationContext());

You can use LifecycleTracker to handle these changes for you.

Parameters

context

The current context.

See also