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