我想获得当前活动
沿的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()