严格模式下的Android TV应用如下初始化我的AAR库:
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
LibraryApplication.init(this);
}}
图书馆
public class LibraryApplication extends Application {
@SuppressLint("StaticFieldLeak")
private static LibraryApplication instance;
@SuppressWarnings("unused")
public static void init(Application application) {
if (instance == null) {
instance = new LibraryApplication(application);
return;
}
throw new RuntimeException("Library already initialized.");
}
private final LibraryActivityHandler activityHandler;
public LibraryApplication(final Application application) {
this.activityHandler = new LibraryActivityHandler(this);
}}
LibraryActivityHandler
class LibraryActivityHandler implements Application.ActivityLifecycleCallbacks {
private Activity currentActivity;
@Override
public void onActivityResumed(Activity activity) {
assert activity != null;
this.currentActivity = activity;
//Just to show you that activity is really not null
currentActivity.getLayoutInflater();
Log.debug("activity set");
}
boolean isActivityNull() {
Log.debug("is null: " + (currentActivity == null));
return currentActivity == null;
}
问题:在日志中,我可以看到“活动集”,以后可以看到“ is null:true”。有人可以向我解释当前的活动如何变为空吗?
在使用Android和Java超过10年之后,
我承认我对此没有太多想法。
编辑:该应用程序还使用Dagger库,严格模式下不会导致此问题。
最佳答案
该问题是由多进程应用程序引起的。