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

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

  •  28-09-2022
  •  | 
  •  

Question

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();
    }
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top