moveTaskToBack(真)总是返回false [英] moveTaskToBack(true) returns false always
问题描述
我知道这已经被问早前这里 &放大器; <一href="http://stackoverflow.com/questions/5312334/how-to-handle-back-button-in-activity/5312426#5312426">here太。他们都没有回答正确(或没有回答所有)。可是,我不知道为什么 moveTaskToBack(真);
总是为我返回false 。可谁能告诉我,为什么和我怎么能解决这个问题?先谢谢了。
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
}
注:从我打电话是一个孩子活动
包含在 tabActivity
既不的活动这是一个主要或 LAUNCHER activity.I不知道是否有差别。
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.
编辑: 其结果是应用程序一点儿也不去background.I希望它去的背景,就像硬件HOME是pressed
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
推荐答案
我不知道为什么 moveTaskToBack(真)
将返回假
为您服务。也许,在你的表现很奇怪?无论如何,你可以做到这一点,而不是调出主屏幕:
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);
不过,要注意的此消息:
你不能模拟上的Home键preSS。 &mdash;罗马盖伊,Android框架工程师
"You cannot simulate a press on the Home key." — Roman Guy, Android framework engineer
我不知道怎么说我的建议的code平方(这是我发现在同一个线程罗马的声明,似乎工作)。
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).
这篇关于moveTaskToBack(真)总是返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!