Skip to content

Commit e99e12b

Browse files
committed
fix: 修正 init 方式, 解決 RePlugin 無法監聽 Activity 生命週期的問題
issue: 原本自動產生 Application 實例, 在 RePlugin 架構中無法正常監聽 Activity 生命週期 要成功註冊 registerActivityLifecycleCallbacks, 必須使用 RePlugin 宿主的 Application 實例進行註冊 solution: 新增帶 Application 的初始化方式, 使用時於 RePlugin 架構中的 Application 帶入宿主的實例進行初始化
1 parent 19af0cf commit e99e12b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib-ui-titlebar/src/main/java/co/bxvip/tools/toast/ToastUtils.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.content.res.Resources;
99
import android.graphics.drawable.GradientDrawable;
1010
import android.os.Build;
11+
import android.support.annotation.Nullable;
1112
import android.util.TypedValue;
1213
import android.view.Gravity;
1314
import android.view.View;
@@ -51,15 +52,19 @@ private ToastUtils() {
5152
// */
5253
// public static void init(Application application, IToastStyle style) {
5354
// initStyle(style);
54-
// init(CommonInit.ctx);
55+
// init(application);
5556
// }
5657

5758
/**
5859
* 初始化 ToastUtils,在Application中初始化
5960
*/
60-
public static void init() {
61+
public static void init(@Nullable Application application) {
6162
isInit = true;
62-
Application application = CommonInit.ctx;
63+
64+
if (application == null){
65+
application = CommonInit.ctx;
66+
}
67+
6368
checkNullPointer(application);
6469
// 初始化 Toast 拦截器
6570
if (sInterceptor == null) {
@@ -260,11 +265,11 @@ public static Toast getToast() {
260265
}
261266

262267
/**
263-
* 检查吐司状态,如果未初始化请先调用{@link ToastUtils#init()}
268+
* 检查吐司状态,如果未初始化请先调用{@link ToastUtils#init(Application application)}
264269
*/
265270
private static void checkToastState() {
266271
if (!isInit) {
267-
init();
272+
init(null);
268273
}
269274
// 吐司工具类还没有被初始化,必须要先调用init方法进行初始化
270275
if (sToast == null) {

0 commit comments

Comments
 (0)