moveTaskToBack(true) returns false always

后端 未结 3 1695
一整个雨季
一整个雨季 2020-12-17 05:29

I know this has been asked earlier here & here too.They are not answered properly (or not answered at all).But,i don\'t know why moveTaskToBack(true); alway

相关标签:
3条回答
  • I came into the similar problem(a child Activity included in a tabActivity), when you call moveTaskToBack(true) in the child activity, it doesn't work, whereas it works in the parent activity. You can call moveTaskToBack(true) in child activity like this: ChildActivity.this.getParent().moveTaskToBack(true)

    0 讨论(0)
  • 2020-12-17 06:14

    Just write:

    @Override
    public void onBackPressed() {
        moveTaskToBack(true);
        //  super.onBackPressed();
    }
    
    0 讨论(0)
  • 2020-12-17 06:16

    I don't know why moveTaskToBack(true) is returning false for you. Perhaps there's something weird in your manifest? At any rate, you can do this instead to bring up the home screen:

    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_HOME);
    this.startActivity(i);
    

    However, be aware of this message:

    "You cannot simulate a press on the Home key." — Roman Guy, Android framework engineer

    I'm not sure how that squares with my suggested code (which I found on the same thread as Roman's statement and seems to work).

    0 讨论(0)
提交回复
热议问题