获取活动名称动态 - 机器人机器人、名称、动态

2023-09-12 22:18:02 作者:低調、綀博不了我の高傲

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

 
精彩推荐
图片推荐