RikkaApps / Shizuku-API

The API and the developer guide for Shizuku and Sui.
MIT License
1.02k stars 244 forks source link

Add `removeAllListeners` if possible #36

Closed qhy040404 closed 7 months ago

qhy040404 commented 1 year ago

While using lambda to add listener in Kotlin, it seems that the listener cannot be removed in this case.

For example,

Shizuku.addRequestPermissionResultListener { _, _ -> doSomething() }

There is no way to remove this particular listener. Since I only added this one listener, it would be better to remove them all at once.

Maybe we can add a function named removeAllListeners in a easy case.

public static void removeAllListeners() {
    RECEIVED_LISTENERS.clear();
    DEAD_LISTENERS.clear();
    PERMISSION_LISTENERS.clear();
}

or divide this function into 3 cases