How to go back to the previously opened application while finishing an Activity in Android

StackOverflow https://stackoverflow.com/questions/21162408

  •  28-09-2022
  •  | 
  •  

Pergunta

I have a Alarm application. When the alarm triggers a activity will be invoked which inflates a layout. There is a "OK" button in this layout. When I click on that I want to go back to my previous application. i.e; if I was using chrome then it should go to chrome, if I was playing some game then it should go back there. Now what happens is it goes to the home page of my Alarm App.

Below is my code for "OK" button:

public void stoptimer(View v) {
        if (null != player) {
            player.stop();
            player.release();
        }
        if (!emailStr.isEmpty()) {
            shareTimeEmail(this, emailStr);
        }
        this.finish();
    }
Foi útil?

Solução

Call moveTaskToBack(true) instead (or both) of finishing the Activity.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top