0

i have a animation runing on my activity, a logo that is rotating....

i call function onBackPressed() that show alert dialogBox "are you sure you want to exit ?" there are two buttons "Yes" or "No"

.....i want my activity pause so that the logo donot rotate while dialog box is open...

here's my code

public override void OnBackPressed()
    {
        AlertDialog.Builder exit = new AlertDialog.Builder(this);
        exit.SetMessage("Are you sure You want to Exit");
        exit.SetCancelable(false);
        exit.SetPositiveButton("yes", (object sender, DialogClickEventArgs e) =>
         {
             this.Finish();
         });
        exit.SetNegativeButton("No", (object sender, DialogClickEventArgs e) =>
         {
         });
        exit.Show();}
Junaid umar
  • 77
  • 1
  • 2
  • 13

2 Answers2

0

Hold a reference to your animation, and call pause on it when showing the dialog :

public override void OnBackPressed()
{
    AlertDialog.Builder exit = new AlertDialog.Builder(this);
    exit.SetMessage("Are you sure You want to Exit");
    exit.SetCancelable(false);
    exit.SetPositiveButton("yes", (object sender, DialogClickEventArgs e) =>
     {
         this.Finish();
     });
    exit.SetNegativeButton("No", (object sender, DialogClickEventArgs e) =>
     {
       myAnimation.resume();
     });
    myAnimation.pause();
    exit.Show();
}

You can use this good example/answer to know how to pause and resume an animation : https://stackoverflow.com/a/10028575/4706693 OR use the simple pause and resume from the Animator class if that's what you're using

Community
  • 1
  • 1
NSimon
  • 5,212
  • 2
  • 22
  • 36
0

You can't pause the activity but the activity's lifecycle method OnPause() will be called when you show your dialog.

You can just stop/pause the animation in the OnPause() method of your acitivty.

Nongthonbam Tonthoi
  • 12,667
  • 7
  • 37
  • 64
  • `public override void OnBackPressed() { OnPause(); AlertDialog.Builder exit = new AlertDialog.Builder(this); exit.SetMessage("Are you sure You want to Exit"); exit.SetCancelable(false); exit.SetPositiveButton("yes", (object sender, DialogClickEventArgs e) => { this.Finish(); }); exit.SetNegativeButton("No", (object sender, DialogClickEventArgs e) => { }); exit.Show(); } protected override void OnPause(){ base.OnPause(); }` – Junaid umar Jun 01 '16 at 10:46
  • You don't call methods like OnPause(), android will call them when required – Nongthonbam Tonthoi Jun 01 '16 at 11:22