Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get main Activity class or class name of my application?

Tags:

android

How to get main Activity class or class name of my application?

Thanks a lot!

like image 453
IgorOK Avatar asked May 13 '12 17:05

IgorOK


People also ask

How do I find my main activity?

This can be found in the application's manifest. The main activity is the activity with the intent-filter whose name is android. intent. action.

Which specifies the class name of the activity?

The only required attribute for this element is android:name, which specifies the class name of the activity.

What is Android Activity name?

An activity represents a single screen with a user interface just like window or frame of Java. Android activity is the subclass of ContextThemeWrapper class. The Activity class defines the following call backs i.e. events. You don't need to implement all the callbacks methods.


2 Answers

This worked perfectly for me in Kotlin:

callingActivity::class.simpleName

or in Java:

activity.getClass().getSimpleName()
like image 72
user2288580 Avatar answered Sep 18 '22 13:09

user2288580


To get your launcher activity use http://developer.android.com/reference/android/content/pm/PackageManager.html#getLaunchIntentForPackage(java.lang.String)

getLaunchIntentForPackage

On this Intent call getComponentName and from the returned CompomemtName call getClassName

http://developer.android.com/reference/android/content/ComponentName.html

like image 22
Lee Avatar answered Sep 18 '22 13:09

Lee