Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
536 views
in Technique[技术] by (71.8m points)

java - moveTaskToBack(true) returns false always

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); always returns false for me .Can anyone tell me why and how could i solve the issue? Thanks in advance.

public void onBackPressed() {       
    boolean r=  moveTaskToBack(true);
    //r is false !! using API LEVEL 8
}

Note:The activity from which i am calling it is a child Activity included in a tabActivity and neither of this is a MAIN or LAUNCHER activity.I don't know if that makes a difference.

EDIT: and as a result the application does'nt go to background.I want it to go to background just as if the hardware HOME is pressed

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...