java - 在 Android Application.onCreate() 方法中检测 Activity/BroadcastReceiver

标签 java android

我需要检测 Activity 或 BroadcastReceiver 是否启动应用程序 - 在 Application.onCreate 方法内部。如果应用程序是由广播接收器启动的,则不应调用 tryLoginOffline()

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        if(calledByActivity) {
            tryLoginOffline();
        }
    }
    //...
}

谢谢!

最佳答案

I need to detect if Activity or BroadcastReceiver starts the application - inside of Application.onCreate method.

抱歉,但没有选择。

Call tryLoginOffline() should not be in case of the application is started by broadcast receiver.

那么该代码不应位于 Application 子类的 onCreate() 方法中。从您的 Activity 中调用它。

关于java - 在 Android Application.onCreate() 方法中检测 Activity/BroadcastReceiver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54707825/

相关文章:

java - 在 Java 的枚举中使用 equals 和字符串

java - 在android studio中,在调试应用程序BluetoothLeGatt时,我得到了以下期望:

java - 在较早的 Android 中显示本周的 7 个日期

android - 在android中单击一次从textview中选择文本

android - 什么是 gradlew 任务 assembleAndroidTest 以及 Android 中的测试应用程序是什么?

Java 最佳实践 : nested getters? 或委托(delegate)?

java - ArrayList<>().contains(Object obj) 的行为

java - 如何打印没有转义符和引号的嵌套 json 对象

Android getMaxAddressLineIndex 为第 1 行返回 0

java - 每种纹理都有一个 OpenGL ES 程序?