Rahul
Rahul

Reputation: 41

How to get the name of layout associated with an activity in activity lifecycle onActivityStarted method?

I need to get layout name of any activity from activity life cycle method.

override fun onActivityStarted(activity: Activity) { Log.d("onActivityStarted", activity.localClassName) }

Upvotes: 0

Views: 388

Answers (1)

Atul Papneja
Atul Papneja

Reputation: 26

I found a solution for this first get view group of your activity like this

val viewGroup = (activity.findViewById(android.R.id.content) as ViewGroup).getChildAt(0) as ViewGroup

then get resources id and by the resources id get resources name like this

val resourceName = activity.resources.getResourceName(viewGroup.sourceLayoutResId)

thats it you have your attached layout path and name with your activity

Log.d("Layout res path", ">>>>>> $resourceName")

Upvotes: 1

Related Questions