Specific Cast invalid exception for context to activity
You can't convert Android.App.Application.Context
to Activity
, as illustrated in the following diagram, they are the different type.

As David Wasser said ;
FinishAffinity()
is not used to "close an application". It is used to remove a number of Activity
s belonging to a specific application from the current task (which may contain Activity
s belonging to multiple applications).
Even if you finish all of the Activity
s in your application, the OS process hosting your app does not automatically go away (as it does when you call System.exit()
). Android will eventually kill your process when it gets around to it. You have no control over this (and that is intentional).
Suggestion :
You could close your app by using the following code :
private void CloseApp()
{
Java.Lang.JavaSystem.Exit(0);// Close this app process
Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
}
Update :
If you use FinishAffinity
in an Activity
, modify your code like this :
public void CloseByFinish()
{
this.FinishAffinity();
}