diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..644b54192d2f2a9a2ac5590a04b0dae64ee7c180 --- /dev/null +++ b/README.en.md @@ -0,0 +1,54 @@ +# App Exception Handling + +### Overview + +This sample shows how to use **hiAppEvent** to obtain the last app exception information, which can be app crash or suspension. + +### Preview +| Default page | Build exception events | Capture abnormal events | +|---------------------------------------|---------------------------------------|---------------------------------------| +| ![](screenshots/device/Preview_1.en.png) | ![](screenshots/device/Preview_2.en.png) | ![](screenshots/device/Preview_3.en.png) | + +### How to Use + +1. Touch **Create app crash event**. After 3 seconds, the app exits. Start the app, and open the app exception page. About 1 minute later, the last abnormal exit information is displayed. +2. Touch **Create app suspension event**. Manually exit the app. Then, start the app, and open the app exception page. About 1 minute later, the last abnormal exit information is displayed. + +### How to Implement + +1. Build application exceptions. For details about the source code, see [Index.ets](./entry/src/main/ets/pages/Index.ets). +2. After the app exits, open the current page and wait for a subscription message notification. After a subscription message is received, use the **onReceive** method in **EventSubscription.ets** to receive the exception information and use **AppStorage.setOrCreate('appEventGroups', exception information data)** to bind the exception information bidirectionally. For details about the source code, see [EventSubscription.ets](./entry/src/main/ets/model/EventSubscription.ets). +3. Use @StorageLink ('appEventGroups') to receive the event group information transferred by the subscription event function, call the **getFaultMessage** method to process the information, and add the processed information to the lazy loading data sources through **this.faultDataSource.pushData(message)**. Use **this.faultDataSource.persistenceStorage()** to perform persistent storage, and use **LazyForEach** to load data to the page. For details about the source code, see [Index.ets](./entry/src/main/ets/pages/Index.ets). +4. The preceding code references the lazy loading data class and persistent storage class. For details about the source code, see [DataSource.ets](./entry/src/main/ets/model/DataSource.ets) and [PreferencesManager.ets](./entry/src/main/ets/model/PreferencesManager.ets). + +### Project Directory + + ``` + ├───entry/src/main/ets + │ ├───entryability + │ │ └──EntryAbility.ets // Entry ability lifecycle callbacks + │ ├───log + │ │ └──Logger.ets // Log utility + │ ├───model + │ │ ├───DataSource.ets // Model layer - lazy loading data sources + │ │ ├───EventSubscription.ets // Data model layer - app event subscription + │ │ ├───MockData.ets // Data model layer - simulation data + │ │ └──PreferencesManager.ets // Data model layer - persistent storage + │ └───pages + │ └──Index.ets // View layer - app exception page + └───entry/src/main/resources // Static resources + ``` + +### Dependencies + +N/A + +### Constraints + +1. The sample app is supported only on Huawei phones running the standard system. + +2. The HarmonyOS version must be HarmonyOS NEXT Developer Beta1 or later. + +3. The DevEco Studio version must be DevEco Studio NEXT Developer Beta1 or later. + +4. The HarmonyOS SDK version must be HarmonyOS NEXT Developer Beta1 or later. diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index fdcec0d5d336b0afbf96a5d66591e2334b2cd068..b039ecb6c10c6bf7f482b4d052b2496f7f9a4a87 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -2,35 +2,35 @@ "string": [ { "name": "application_exception_crash_event", - "value": "Click to build application crash event" + "value": "Create app crash event" }, { "name": "application_exception_freeze_event", - "value": "Click to build application stuck event" + "value": "Create app suspension event" }, { "name": "application_exception_application_fault_title", - "value": "Application fault message" + "value": "Obtain app exception information" }, { "name": "application_exception_application_fault_description", - "value": "Click to build an abnormal event. After 3 seconds, the system abnormal event will be triggered. You need to restart the application and enter this page to obtain the reason for the last abnormal exit" + "value": "Build an exception event, and the event is triggered 3s later. Start the app and open the current page. About 1 minute later, the last abnormal exit information is displayed." }, { "name": "application_exception_crash_event_message", - "value": "After 3 seconds, the system crash event will be triggered, and the application needs to be restarted to enter this page to obtain the last login exception information" + "value": "The crash event is triggered 3s later. Start the app and open the current page to obtain the last abnormal exit information." }, { "name": "application_exception_freeze_event_message", - "value": "After 3 seconds, if the system freezes, the application needs to be restarted and this page should be accessed to obtain the last login exception information" + "value": "The suspension event is triggered 3s later. Start the app and open the current page to obtain the last abnormal exit information." }, { "name": "application_exception_no_message", - "value": "no_message" + "value": "None" }, { "name": "application_exception_data_delay_toast", - "value": "数据大约在1-3min会进行更新" + "value": "The data is updated in about 1-3 minutes." } ] } diff --git a/screenshots/device/Preview_1.en.png b/screenshots/device/Preview_1.en.png new file mode 100644 index 0000000000000000000000000000000000000000..7d3b70ddd5d2e27955fca88025891bea36a53e23 Binary files /dev/null and b/screenshots/device/Preview_1.en.png differ diff --git a/screenshots/device/Preview_2.en.png b/screenshots/device/Preview_2.en.png new file mode 100644 index 0000000000000000000000000000000000000000..765814ef801870a09c6e3a71eeba74d99e2cc982 Binary files /dev/null and b/screenshots/device/Preview_2.en.png differ diff --git a/screenshots/device/Preview_3.en.png b/screenshots/device/Preview_3.en.png new file mode 100644 index 0000000000000000000000000000000000000000..0daa8682bbc56acf0fd5723fee4cec2c1d734f90 Binary files /dev/null and b/screenshots/device/Preview_3.en.png differ