ViewController name

ViewController 'name ’ attribute,when I use build --prod ,the name attribute return ‘e’,How to get the correct name when use --prod?

That property is private. Don’t attempt to access it.

ok ,thank you very much,could you tell me how to get the name of the ViewController?

IMHO, a well-designed app has no need for that. If you want something to happen only when a specific page is active, use the lifecycle events to register and unregister actions. That way, the code is localized to the relevant page, instead of being spread out in some massive switch that tries to handle all cases.

Thank you,I want something happen when all page changes,and I have to get the page name.could you give me some advice?

As I said before, I think this is a bad design. Please rethink what you are doing so that you do not need this information, and your app will be better for it.

There are Situations beside a massive Switch (which is indeed bad) where this is very useful.
To me, i am using a split-pane on a Tablet for providing an Menu to quickly jump to different Pages in the App.
Every Page also have a next/back Button so sequential Navigation.
The Pages are lazy loaded where the ViewController Name / PageName comes into play.
This way i’m having an elegant Solution to keep the acitve Page and the Menu in sync on squential navigation (by highligting the Menu Item) by subscribing to viewDidEnter(ViewController) on Appstart and only using navpush/navpop on the Pages.
To me coding around this Limitation makes my design at least not better.

1 Like

Do you mean the page name? like this:


getActive() also returns a ViewController, same Problem

I agree with waybackrider. I think being able to get the active page name could be useful in various different circumstances (none of which involve long switch statements). Why is it possible to get the active page, but not determine it’s name? That seems a little absurd.

Technically? Because production builds minify class names.

1 Like

finally,I add getClassname() to each class.

As explained here

We can use

//In debug mode alert value is 'HomePage'
//In production/ signed apk alert value is 'HomePage'
if ( === 'HomePage') {