Android的 - 动态地获取当前活动的前景 [英] Android - Dynamicly Get the Current Activity in Foreground

查看:333
本文介绍了Android的 - 动态地获取当前活动的前景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的情况是:

  1. 在一个线程中,甚至被触发。
  2. 当前活动需要检索。
  3. 然后一个对话框,在该活动创建和显示。

问题:  至于我搜索有没有办法来检索在前台当前的活动。

Problems: As far as I've searched there is no way to retrieve the current activity in the foreground.

额外的信息:  这需要能够在多个活动处理。因此,它可以弹起的活动为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.

推荐答案

我不知道如果这是你在找什么,但它似乎pretty的简单。 <一href="http://iamvijayakumar.blogspot.com/2011/09/get-current-activity-and-package-name.html">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());

希望这有助于。

Hope this helps.

这篇关于Android的 - 动态地获取当前活动的前景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆