开发者

How to get an instance of a paused activity?

开发者 https://www.devze.com 2023-04-08 00:39 出处:网络
Is there any way to get t开发者_如何学Che instance of a paused Activity? I need to run a public method from another Activity when it is paused, and there is no way I can use a static method That doesn

Is there any way to get t开发者_如何学Che instance of a paused Activity? I need to run a public method from another Activity when it is paused, and there is no way I can use a static method


That doesn't make sense from the Android perspective. If it's something that'll affect the Activity's UI, then centralize the information in an external class and read it inside paused Activity's onResume.


You can store the instance of an activity in a Hashtable with a unique key in the onPause() method(), and retrieve it whenever you want it and work on it. of check for mull pointer exception coz dvm/a-os may have killed the activity if it thinks thats the best thing to do.

I am not sure if this will work, but the official method i guess could be: you can try retrieving all the activities using ContextManager/ActivityManager apis and iterate through each n do the needful.

0

精彩评论

暂无评论...
验证码 换一张
取 消