Android getting Activity from Context

Sometimes we pass context of an activity as a parameter to some other function and later we might want the activity too. So instead of passing the activity also to that function, we can get the activity from context itself.

Method 1

You can get the activity from the context by type casting the context to activity.

Activity activity = (Activity) _context;