Problem
When modularizing, I tried to separate modules like SearchListener and CallManager from MainActivity. However, when responding to events, it was inevitable to change the state of other resources, so it was necessary to obtain their handles. Thus, MainActivity also needed to be passed in as a handle.
What bothered me even more was that due to some asynchronous events (such as requesting permissions), the trigger was in the module (CallManager), while the receiver was in the main view (MainActivity). The preserved parameters then needed to be passed back to MainActivity, going back and forth like this, which made me reflect on the problems in my modularization approach.
Author: 木鸟杂记 https://www.qtmuniao.com, please indicate the source when reposting
Details
1 | CallManager.java |
In Activity, a call event is received and CallManager is invoked, then permissions are requested within it. Using the Set method, PhoneNumber is passed back to Activity. My initial thought was that the code tightly coupled with Activity, such as requesting permissions and executing callback functions after being granted permissions, could be written in MainActivity, while CallManager would only handle the call logic. However, a class variable is still needed to save the phone number for parameter passing between requesting permissions and executing the callback.
