evanmcdonnal evanmcdonnal - 1 year ago 89
Android Question

Get Activity name dynamically - android

I'd like to get the name of the current

to be sent along in the URI of an
. Is there a way to do this without referring specifically to the

I know I can do
but this is just a less efficient way of hard coding "myActivity" since I'm making a static reference to my
. 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).

Answer Source

Use this.getClass().getSimpleName() to get the name of the Activity.

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download