碎片有"getActivity()"。模仿这种行为的其他活动有哪些?

Fragments have "getActivity()". What do additional Activities have that mimics this behavior?

在使用 Java 的 Android 开发中,Fragments 有 "getActivity()",这将为您提供 MainActivity 的引用。我想知道是否有一种方法可以从不同的 Activity 而不是 Fragment.

获取与 MainActivity 相同类型的引用
IE: (Not in code, more of a diagram)

    MainActivity - "this"          : MainActivity reference
    Fragments    - "getActivity()" : MainActivity reference
    Activity 2   - "this"          : Activity 2 reference
    Activity 2   - ????            : MainActivity reference
    Activity 3   - "this"          : Activity 3 reference
    Activity 3   - ????            : MainActivity reference

在这个例子中,我试图直观地向您展示我正在寻找的东西。本质上,填写“????” (希望它有意义)

我尝试了很多东西并进行了大量研究。有很多帖子描述了一些在活动之间传递数据的正确方法和更多错误的方法,但这与在活动之间传递数据无关。它是关于从其他活动中引用 MainActivity。

是否可以从其他活动访问 MainActivity?或者这只是不好的做法?看起来它应该像 getActivity() 来自片段一样简单,但也许我错过了这个概念。

Things I have tried that have not worked are. 
1. Passing the MainActivity reference itself through an Intent, this fails because Activities are not Parceable. (I can pass parceable data and other variables just fine, but not an Activity)
2. I have tried making the activity a child of MainActivity in the AndroidManifest and as well as adding meta data claiming it is the child. This is help get a non_null return from get getParentActivityIntent(); However, it does not provide any way to get that MainActivity reference from that.
3. I have tried getParent(); This always returns null.
4. I have tried getCallingActivity(); This always returns null.
5. I have tried getApplicationContext(); This doesn't seem to have a way to funnel down to a MainActivity reference.
6. Definitely many more things that aren't worth mentioning or forgotten.

我基本上被路障了 2 天,现在正在研究这个,直到我想出一种方法来获得这个参考。有很多你认为相关的帖子,但实际上并没有通过真正的参考,也没有直接或间接回答我的问题。在 Android Java 中总是阻碍我的事情是无法引用我需要引用的东西。每一个。单身的。时间。当您可以访问您需要访问的内容时,其他一切通常都非常顺利。 :)

感谢您的帮助和时间。

活动不是这样进行的,不是。每个 activity 都完全独立于其他 activity,您无法安全地访问任何其他 activity。这就是为什么存在于单个 activity 之类的片段中的抽象很有用,也是为什么推荐使用 Single Activity pattern