如何完成()的活动时,Home键pressed [英] How to finish() an Activity when Home button pressed

查看:132
本文介绍了如何完成()的活动时,Home键pressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个复杂的原因,我需要能够完成()我的活动,当用户presses HOME键。

For a complicated reason I need to be able to finish() my activities when the user presses the HOME button.

下面的故事是,我有一个主屏幕小工具,启动我的应用程序,有一个完全透明的活动(因此主屏幕不断显示,即使我的活动运行)的不同部分。如果previous活动通过Home键终止,他们被带到了前台,并掩盖了主屏幕。

The story here is that I have a homescreen widget that launches a different part of my application that has a completely transparent activity (so the homescreen keeps showing even though my activity is running). If the previous activities were terminated via Home button, they are brought to the foreground and obscure the home screen.

或者也可以,我可以有新的活动以某种方式强制完成()的previous活动?

Or as alternative, can I have the new activity somehow force finish() the previous activity?

推荐答案

什么

android:launchMode="singleTask"

android:launchMode="singleInstance"

在你的表现?我觉得 singleTask 是你想要的,但你在做什么即时通讯仍然没有晶莹剔透。

in your manifest? i think singleTask is the one you want, but im still not crystal clear on what you are doing.

系统创建在一个新的任务和路线的意图给它的根的活性。然而,如果已经存在的活性的一个实例,该系统路由通过调用其onNewIntent意图现有实例()方法,而不是创建一个新的。 singleTask

"The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one." singleTask

@Override
void onPause() {
   super.onPause();
   finish();
}

开发文档: Acitvity生命周期完成

这篇关于如何完成()的活动时,Home键pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆