How Plugins and Composite implementations work together
masterCompositeAndroid uses a 'Composition over inheritance' approach to add functionality to Android components without creating deep inheritance hierarchies.
Instead of extending a BaseActivity that contains everything, you extend a composite implementation (like CompositeActivity) and add specific Plugins via the constructor.
Key Lifecycle Rules:
- Registration: Always add plugins in the constructor. Do not add them in
onCreate(), as many lifecycle methods are called beforeonCreate()and the plugin needs to be present to intercept them. - Execution: Plugins can intercept every method of the Activity/Fragment. You can choose to execute code before calling
super, after callingsuper, or by explicitly not callingsuperat all.
public class MainActivity extends CompositeActivity {
final LoadingIndicatorPlugin loadingPlugin = new LoadingIndicatorPlugin();
public MainActivity() {
addPlugin(new ViewTrackingPlugin("Main"));
addPlugin(loadingPlugin);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ...
// example usage of the LoadingIndicatorPlugin
loadingPlugin.showLoadingIndicator();
}
}