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
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)
Just write:
@Override
public void onBackPressed() {
moveTaskToBack(true);
// super.onBackPressed();
}
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).