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

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

  •  28-09-2022
  •  | 
  •  

Вопрос

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();
    }
Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top