I have a custom view inside an activity, which i am launching with an Application context.
When i call the View.getContext()
from within my CustomView
and try to cast it:
Activity activity = (Acitivity)View.getContext();
It gives an error that cannot cast the Context
from Application
to Activity
.
Has someone faced this problem before ??? please help
As Romain Guy says in this post, there is no guarantee that the Context
used by your View
is an Activity
. Also, if you are using the Applcation
Context
you cannot cast it to the Activity
Context
; they are different. This link gives a great explanation of all the different flavors of Context
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With