You are passing the Application Context
not the Activity Context
with
getApplicationContext();
Wherever you are passing it pass this
or ActivityName.this
instead.
Since you are trying to cast the Context
you pass (Application not Activity as you thought) to an Activity
with
(Activity)
you get this exception because you can't cast the Application to Activity
since Application is not a sub-class of Activity
.