本文介绍了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-动态获取前景中的当前活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!