当前位置: 动力学知识库 > 问答 > 编程问答 >

android - How Do I Get The Currently Running Activity In My Application?

问题描述:

I have a class that needs to access my application's main activity, but by design outside of my control I cannot pass an instance to it. Its purpose is to dynamically create a view and set it to the activity.

Is there a way for me to access the main activity through a static method? Or is there an alternative?

网友答案:

According to the comments above, maybe you need just static instance of context initialized in Application/Activity onCreate?

分享给朋友:
您可能感兴趣的文章:
随机阅读: