获取活动名称动态 - 机器人 [英] Get Activity name dynamically - android

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

问题描述

我想获得当前活动沿的URI中的Htt prequest 。有没有办法做到这一点没有特指的活动

I'd like to get the name of the current Activity to be sent along in the URI of an HttpRequest. Is there a way to do this without referring specifically to the Activity?

我知道我可以做 myActivity.class.toString()但是这仅仅是一个低效率的硬编码myActivity的方式,因为我做的静态引用我的活动。有没有做到这一点使用像'这个'(这顺便说一句实际上并没有在这里工作,因为它返回比期望的更多信息)一个更普遍的方式。

I know I can do myActivity.class.toString() but this is just a less efficient way of hard coding "myActivity" since I'm making a static reference to my Activity. Is there a more general way to do this using something like 'this' (which btw doesn't actually work here because it returns more information than what's desired).

推荐答案

使用 this.getClass()。getSimpleName()获得活动的名称。

从评论,如果您在上下文中的 OnClickListener (或其他内部类),手动指定类:

From the comments, if you're in the context of an OnClickListener (or other inner class), specify the class manually:

MainActivity.class.getSimpleName()

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

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