I have a custom activitygroup that adds and removes views to the stack.
I override the dispatchKeyEvent to check for certain keys pressed.
the problem is that I need to check the type of the current focused view like this:
View v=getCurrentFocus();
when I check for the type of the view,
it returns a type like this
com.android.internal.policy.impl.PhoneWindow$DecorView
what is this type and can I cast any class object to this type ?
thanks
No you can’t just cast any class object to this type! Best practice is that you should only ever cast up the class hierarchy, or if you really must cast down make sure you check the type first using the instanceof operator.
Also, judging by the package name it’s an internal android class, so you do not want any references to that in your code – if it’s internal, it’s non api. They could change it at any point and your app would immediately be broken.
Why are you checking the type of the view?
Are you looking for a particular type?
If so, it’s be safer to do (for example):
Or if it is the decor view you are interested in use getDecorView instead of getCurrentFocus .