How to return to the latest launched activity when re-launching application after pressing HOME?

后端 未结 6 1700
臣服心动
臣服心动 2020-12-01 08:15

Familiar scenario: I have a Main activity that launches a Game activity when a button is pressed. If the user presses HOME, and then launches my applicatio

6条回答
  •  温柔的废话
    2020-12-01 08:36

        @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { 
            // Activity was brought to front and not created, 
            // Thus finishing this will get us to the last viewed activity 
            finish(); 
            return; 
        } 
    
        // Regular activity creation code... 
    } 
    

提交回复
热议问题