Custom Scope Annotation

Purpose

Within the dependency injection framework used in this project, managing the lifecycle and scope of injected objects is critical to ensuring resource efficiency, modularity, and consistent behavior. The **Custom Scope Annotation** named `@ActicityScope` addresses this need by defining a specific scope that limits the lifetime of dependencies to the lifecycle of an activity instance.

This scope ensures that objects annotated with `@ActicityScope` are instantiated once per activity and shared within that activity’s component graph, avoiding unnecessary multiple instances and enabling clean, contextual injection tailored to each activity.

Functionality

The `@ActicityScope` annotation is a lightweight custom qualifier that:

This behavior supports patterns where certain objects (e.g., `FsmPlayer`, `PlayerControllerUI`) need to be consistent and shared during the entire active period of an activity but should be discarded afterward to avoid memory leaks or stale state.

Code Snippet

@Scope
@Retention(RetentionPolicy.RUNTIME)
public @interface ActicityScope {
}

This concise declaration serves as a marker for Dagger to group and manage scoped instances.

Integration and Relationship

Example Use in Component Declaration

@ActicityScope
@Component(modules = {PlayerModuleDefault.class})
public interface FsmComonent {
    void inject(DoubleViewTubiPlayerActivity activity);
    // Other injection targets
}

Here, `@ActicityScope` ensures that all dependencies provided by `PlayerModuleDefault` and injected into `DoubleViewTubiPlayerActivity` are scoped to the activity.

Diagram

classDiagram
    class ActicityScope {
        <<interface>>
        +@Scope
        +@Retention(RUNTIME)
    }
    class FsmComonent {
        <<component>>
        +inject(activity)
    }
    class PlayerModuleDefault {
        <<module>>
        +providesDependencies()
    }
    FsmComonent ..|> ActicityScope : scoped with
    PlayerModuleDefault ..|> ActicityScope : scoped provides

This class diagram illustrates how `@ActicityScope` acts as a marker interface linking Dagger components and modules to a specific scoped lifecycle, governing the instances they supply and manage.


By defining `@ActicityScope`, the project ensures that all activity-level dependencies have a controlled lifecycle matching the activity, promoting modularity, memory efficiency, and clear dependency management within the Android media player framework.