Home > Mobile >  How to get the name of layout associated with an activity in activity lifecycle onActivityStarted me
How to get the name of layout associated with an activity in activity lifecycle onActivityStarted me

Time:01-20

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

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

CodePudding user response:

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")

  •  Tags:  
  • Related