简体   繁体   English

如何获取暂停活动的实例?

[英]How to get an instance of a paused activity?

Is there any way to get the 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 我需要在暂停时从另一个Activity运行一个公共方法,并且我无法使用静态方法

That doesn't make sense from the Android perspective. 从Android的角度来看,这没有任何意义。 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. 如果它会影响Activity的UI,那么将信息集中在一个外部类中,并在暂停的Activity的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. 您可以使用onPause()方法()中的唯一键将活动的实例存储在Hashtable中,并在需要时随时检索它并对其进行处理。 of check for mull pointer exception coz dvm/a-os may have killed the activity if it thinks thats the best thing to do. 检查mull指针异常coz dvm / a-os可能已经杀死了活动,如果它认为这是最好的事情。

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. 我不确定这是否可行,但我猜的官方方法可能是:您可以尝试使用ContextManager / ActivityManager apis检索所有活动,并遍历每个n做必要的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM