### Java: Early Module Initialization with ARouter Source: https://github.com/goldze/mvvmhabitcomponent/blob/master/README.md This Java code snippet demonstrates the onInitAhead method within ModuleLifecycleConfig, used for early initialization of modules. It specifically shows the setup for ARouter, including enabling logging and debug mode for development, and initializing the framework as early as possible within the application lifecycle. ```Java @Override public boolean onInitAhead(Application application) { KLog.init(true); //初始化阿里路由框架 if (BuildConfig.DEBUG) { ARouter.openLog(); // 打印日志 ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险) } ARouter.init(application); // 尽可能早,推荐在Application中初始化 return false; } ``` -------------------------------- ### Configure MVVMHabit Repository and Dependency in Gradle Source: https://github.com/goldze/mvvmhabitcomponent/blob/master/README.md This snippet shows how to add the JitPack repository to your project's root `build.gradle` file and then include the MVVMHabit library as an implementation dependency in your module's `build.gradle`. This setup is essential for integrating the MVVMHabit framework into your Android project. ```Gradle allprojects { repositories { ... google() jcenter() maven { url 'https://jitpack.io' } } } ``` ```Gradle dependencies { ... implementation 'com.github.goldze:MVVMHabit:?' } ``` -------------------------------- ### Java: Defining Module Initialization Interface (IModuleInit) Source: https://github.com/goldze/mvvmhabitcomponent/blob/master/README.md This Java interface, IModuleInit, defines two methods for module initialization: onInitAhead for early initialization and onInitLow for later initialization. Modules requiring dynamic configuration in the Application should implement this interface to standardize their lifecycle management. ```Java public interface IModuleInit { //初始化优先的 boolean onInitAhead(Application application); //初始化靠后的 boolean onInitLow(Application application); } ``` -------------------------------- ### Java: Implementing Module Initialization in Application onCreate Source: https://github.com/goldze/mvvmhabitcomponent/blob/master/README.md This Java code shows how to invoke the module initialization methods (initModuleAhead and initModuleLow) from within the host application's onCreate method. It utilizes the ModuleLifecycleConfig singleton to manage the staggered initialization of various components. ```Java @Override public void onCreate() { super.onCreate(); //初始化组件(靠前) ModuleLifecycleConfig.getInstance().initModuleAhead(this); //.... //初始化组件(靠后) ModuleLifecycleConfig.getInstance().initModuleLow(this); } ``` -------------------------------- ### Java: ARouter Navigation to Another Component Source: https://github.com/goldze/mvvmhabitcomponent/blob/master/README.md This Java snippet demonstrates how to use ARouter to navigate from one component (Component A) to a page in another component (Component B). It shows building a route with a specified URL and optionally passing string parameters. ```Java ARouter.getInstance() .build(router_url) .withString(key, value) .navigation(); ``` -------------------------------- ### Java: Subscribing and Receiving RxBus Events Source: https://github.com/goldze/mvvmhabitcomponent/blob/master/README.md This Java code shows how to subscribe to and receive events published via RxBus. It demonstrates creating an observable for a specific event type (_Login.class), subscribing with a Consumer to handle the received data, and managing the subscription lifecycle with RxSubscriptions. ```Java subscribe = RxBus.getDefault().toObservable(_Login.class) .subscribe(new Consumer<_Login>() { @Override public void accept(_Login l) throws Exception { //登录成功后重新刷新数据 initData(); //解除注册 RxSubscriptions.remove(subscribe); } }); RxSubscriptions.add(subscribe); ``` -------------------------------- ### Java: Sending Data with RxBus Source: https://github.com/goldze/mvvmhabitcomponent/blob/master/README.md This Java snippet demonstrates how to send an event or data using RxBus. It shows creating an instance of a custom event class (_Login) and posting it to the default RxBus instance, allowing other components to subscribe and receive this event. ```Java _Login _login = new _Login(); RxBus.getDefault().post(_login); ``` -------------------------------- ### Configure ARouter Annotation Processor and Dependencies in Gradle Source: https://github.com/goldze/mvvmhabitcomponent/blob/master/README.md This snippet demonstrates how to configure the ARouter annotation processor within your module's `defaultConfig` block and add the necessary ARouter API and compiler dependencies. This configuration is crucial for enabling ARouter's routing and inter-module communication capabilities in your componentized Android application. ```Gradle defaultConfig { ... javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] } } } ``` ```Gradle dependencies { api 'com.alibaba:arouter-api:?' annotationProcessor 'com.alibaba:arouter-compiler:?' } ``` -------------------------------- ### Java: Defining ARouter Activity Paths Source: https://github.com/goldze/mvvmhabitcomponent/blob/master/README.md This Java class RouterActivityPath provides a standardized way to define ARouter paths for activities within different components. It uses static nested classes to logically group paths, ensuring consistency and ease of use across the project. ```Java public class RouterActivityPath { /** * 主业务组件 */ public static class Main { private static final String MAIN = "/main"; /*主业务界面*/ public static final String PAGER_MAIN = MAIN +"/Main"; } } ``` -------------------------------- ### Java: Receiving Parameters with ARouter @Autowired Source: https://github.com/goldze/mvvmhabitcomponent/blob/master/README.md This Java code illustrates how to receive parameters passed via ARouter in the target component (Component B). The @Autowired annotation is used to automatically inject the value associated with a specific key into a field. ```Java @Autowired(name = key) String value; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.