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

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

问题描述

这里是这样的情况:


  1. 在线程中触发一个事件。

  2. 当前活动需要检索。

  3. 然后在该活动上创建一个对话框并显示。

问题:
就我所搜索而言,没有办法在前台检索当前活动。

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屋!

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