2016-11-26 3 views
0

Ich habe eine Ansicht GifImageButton. Ich möchte seine Animation starten und dann die Aktivität neu starten.Verzögerung Animation vor dem Neustart der Aktivität

Das Problem ist, dass ich möchte, dass die Animation 3 Sekunden dauert, bevor Sie die Aktivität neu starten.

Wie kann ich es tun?

dies ist mein Code:

myGifImageButton.setImageResource(R.drawable.animation); 
Intent intent = getIntent(); 
finish(); 
if (intent != null) { 
    startActivity(intent); 
} 

Als ich las, der bessere Weg ist ein lauffähiges so versucht, verwende ich das, aber ich habe es nicht gelingen:

// start the animation 
myGifImageButton.setImageResource(R.drawable.animation); 

// delay the animation 
mHandler = new Handler(); 
final Runnable r = new Runnable() { 
    void run() { 
     handler.postDelayed(this, 3000); 
    } 
}; 
handler.postDelayed(r, 3000); 

// restart the activity 
Intent intent = getIntent(); 
finish(); 
if (intent != null) { 
    startActivity(intent); 
} 

so Wie kann ich die Animation vor dem Neustart der Aktivität verzögern?

Antwort

1

Yor Runnable ist falsch - Sie sind ständig die gleiche Runnable erneut, die nichts tut.

Statt so etwas wie dies versuchen:

// start the animation 
myGifImageButton.setImageResource(R.drawable.animation); 

// delay the animation 
mHandler = new Handler(); 
final Runnable r = new Runnable() { 
    void run() { 
     // restart the activity 
     Intent intent = getIntent(); 
     finish(); 
     if (intent != null) { 
      startActivity(intent); 
     } 
    } 
}; 
handler.postDelayed(r, 3000); 
+0

König !! Vielen Dank! Ich habe jetzt den Punkt "Lauf" .. :) –

Verwandte Themen