Search code examples
androidandroid-activityreturnbackpressed

Return to previous activity using onBackPressed() without finish()?


I have 2 activities. Activity1 lists a bunch of songs and when one is selected, it go plays the selected song in Activity2. Now I can press Back to go back to Activity1 but I overridden the onBackPressed to start an animation when it is pressed. Since I did that, it never goes back to the previous activity. I don't want to call finish() because it will stop the music and the moveTaskToBack method just hides my whole application. Basically what I want to do is have Activity2 play an animation and go back to Activity1 without finishing or hiding the app. I don't know if making a new Intent to go back is the right way to do this.


Solution

  • Just call super.onBackPressed () just after your Animation code finishes.

    No need to do anything else...