Android - 在前台动态获取当前活动 [英] Android - Dynamically Get the Current Activity in Foreground
本文介绍了Android - 在前台动态获取当前活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
情况如下:
- 在线程中触发了一个事件.
- 需要检索当前活动.
- 然后在该活动上创建一个对话框并显示出来.
问题:据我搜索,没有办法在前台检索当前活动.
Problems: As far as I've searched there is no way to retrieve the current activity in the foreground.
额外信息:这需要能够在多个活动中处理.因此,它可以在 Activity-A 或 B 或 C 中弹出.
Extra info: This needs to be able to be handled in multiple activities. So, it can be popped-up in Activity-A or B or C.
推荐答案
我不确定这是否是您要查找的内容,但看起来很简单.http://iamvijayakumar.blogspot.com/2011/09/get-current-activity-and-package-name.html
I'm not sure if this is what you're looking for, but it seemed pretty straightforward. http://iamvijayakumar.blogspot.com/2011/09/get-current-activity-and-package-name.html
ActivityManager am = (ActivityManager) this .getSystemService(ACTIVITY_SERVICE);
List<RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
Log.d(WebServiceHelper.TAG, "CURRENT Activity ::" + taskInfo.get(0).topActivity.getClassName()+" Package Name : "+componentInfo.getPackageName());
希望这会有所帮助.
这篇关于Android - 在前台动态获取当前活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文