I have implemented a countdown class in my app and i intend to close this app when the OnFinish()
method in the class is called in OnCreate
after future
parameter expires.
I tried to create an instance of my activity class and then the method FinishAffinity
but it didnt work, Here is my code...
public class MainActivity : AppCompatActivity
{
private GLSurfaceView glView;
public static Android.App.AlertDialog.Builder builder;
public static bool g = false;
protected override void OnCreate(Bundle savedInstanceState)
{
MyTimer myTimer = new MyTimer(10000, 1000);
myTimer.Start();
myTimer.OnTick(1000);
myTimer.OnFinish();
}
}
public class MyTimer : CountDownTimer
{
private int a = 10;
public MyTimer(long future, long interval) : base(future, interval)
{
}
public override void OnFinish()
{
//There is an error for accessing the method directly so i tried instantiating the class and then calling the Finish Method
MainActivity y= new MainActivity();
//Call method to finish all underlying activities
y.FinishAffinity();
}
public override void OnTick(long millisUntilFinished)
{
int u = a--;
MyToast.MakeText(Application.Context, "this app will close in " + u + " " + "seconds", ToastLength.Short).Show();
}
}
The FinishAffinity
method in the OnFinish
method is not working so is there any way to call this from outside the class without creating a static to non-static reference error