Search code examples
androidandroid-activity

Sending Activity to background without finishing


How can I make an activity go to background without calling its finish() method and return to the Parent activity that started this? I tried so much but I could not find a solution. So if you guys could help I would be very thankful.


Solution

  • The following will work if the Activity is running in a different task to its parent. To achieve this, see http://developer.android.com/guide/topics/manifest/activity-element.html#lmode.

    public void onBackPressed () {
        moveTaskToBack (true);
    }
    

    The current task will be hidden, but its state will remain untouched, and when it is reactivated it will appear just as it was when you left it.