gpt4 book ai didi

Android:如何知道应用程序类中的组件类型?

转载 作者:行者123 更新时间:2023-11-29 14:47:08 25 4
gpt4 key购买 nike

我正在扩展 Application 类以满足额外的自定义需求。我正在其中调用一个方法。正如预期的行为,它正在为 Android 组件类型(ActivityServiceBroadcast receiver 等)调用,但我想要也只能在 Activity 上调用。还有其他方法可以解决这个问题吗?

public class MyApplication extends Application {

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

// the below method needs to invoked only for service
// but now called for all application components
myCustomMethod();
}

....
}

最佳答案

But I want that too be invoked only on Activity.

做不到。如果应用程序的一个组件打开,应用程序实例将运行。

你需要在另一个类中做定制的事情,并在你想要的组件实例打开时打开它。

关于Android:如何知道应用程序类中的组件类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31705521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com