How to reference the current or main activity from another class

后端 未结 13 1038
难免孤独
难免孤独 2021-01-30 12:39

I often find myself needing to access methods that require referencing some activity. For example, to use getWindowManager, I need to access some Activity. But ofte

13条回答
  •  渐次进展
    2021-01-30 13:19

    There are many ways for Activities communication.

    you can use:

    • the startActivityForResult method

    • a system of broadcast message and receiver (you can broadcast an event from the actual activity, and register a receiver in the target activity. Remember that the target activity must be previously initialized and non finished)

    • as you say, store a reference of the target activity wherever you need.

提交回复
热议问题