### Initializing HermesEventBus in Application onCreate
Source: https://github.com/xiaofei-it/hermeseventbus/blob/master/README.md
This Java code demonstrates the essential initialization step for HermesEventBus. It should be called within the `onCreate` method of the application's main class, passing the application context. This setup is crucial for the library to properly manage both in-process and inter-process communication, serving as the primary initialization for single-app usage and for the main app in multi-app scenarios.
```Java
HermesEventBus.getDefault().init(this);
```
--------------------------------
### Connecting HermesEventBus to Main App from Other Apps
Source: https://github.com/xiaofei-it/hermeseventbus/blob/master/README.md
This Java snippet shows how other applications connect to the main application's HermesEventBus instance for inter-app communication. The `connectApp` method is called in the `onCreate` of the other app's application class, providing its context and the package name of the main app to establish the connection.
```Java
HermesEventBus.getDefault().connectApp(this, packageName);
```
--------------------------------
### Registering and Posting Events with HermesEventBus
Source: https://github.com/xiaofei-it/hermeseventbus/blob/master/README.md
Demonstrates the fundamental usage of HermesEventBus to register an object for event reception and to post new events. This snippet highlights the replacement of standard EventBus with HermesEventBus for IPC scenarios.
```Java
HermesEventBus.getDefault().register(this);
HermesEventBus.getDefault().post(new Event());
```
--------------------------------
### Registering and Posting Events with HermesEventBus
Source: https://github.com/xiaofei-it/hermeseventbus/blob/master/README.md
This snippet shows how to register an object to receive events and how to post a new event using HermesEventBus. It highlights that `HermesEventBus` should be used as a direct replacement for `EventBus` for all event-related operations, including both in-process and inter-process communication.
```Java
HermesEventBus.getDefault().register(this);
HermesEventBus.getDefault().post(new Event());
```
--------------------------------
### Adding HermesEventBus Library Dependency
Source: https://github.com/xiaofei-it/hermeseventbus/blob/master/README.md
This code block shows how to include the HermesEventBus library in an Android project using either Gradle or Maven. The dependency declaration makes the library's classes available for use in the application, whether for single-app or multi-app configurations.
```Gradle
dependencies {
compile 'xiaofei.library:hermes-eventbus:0.3.0'
}
```
```Maven
xiaofei.library
hermes-eventbus
0.3.0
pom
```
--------------------------------
### Declaring HermesService in AndroidManifest for Main App
Source: https://github.com/xiaofei-it/hermeseventbus/blob/master/README.md
This XML snippet shows how to declare the `HermesService` in the `AndroidManifest.xml` of the main application when setting up inter-app communication. This service is crucial for enabling the main app to act as the central hub for event routing between different applications.
```XML
```
--------------------------------
### Annotating Event Subscriber Methods in Java
Source: https://github.com/xiaofei-it/hermeseventbus/blob/master/README.md
This snippet demonstrates the correct way to define an event subscriber method in HermesEventBus (based on EventBus 3.0.0). Instead of using 'onEventXXX' naming convention, methods must be annotated with `@Subscribe` to receive events. The `threadMode` attribute specifies the thread on which the event will be delivered.
```Java
@Subscribe(threadMode = ThreadMode.MAIN)
public void showText(String text) {
textView.setText(text);
}
```
--------------------------------
### Destroying HermesEventBus Instance
Source: https://github.com/xiaofei-it/hermeseventbus/blob/master/README.md
Illustrates the critical step of destroying the HermesEventBus instance when a process no longer requires event posting or reception. This action is essential to prevent `android.os.DeadObjectException` and other potential issues, although these exceptions may not crash the application.
```Java
HermesEventBus.getDefault().destroy();
```
--------------------------------
### Destroying HermesEventBus Instance
Source: https://github.com/xiaofei-it/hermeseventbus/blob/master/README.md
This Java code demonstrates how to properly shut down the HermesEventBus instance when a process no longer needs to send or receive events. Calling `destroy()` is important to prevent `android.os.DeadObjectException` and other potential issues related to IPC resource management.
```Java
HermesEventBus.getDefault().destroy();
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.