手柄强行关闭?

发布于 2024-09-25 16:27:40 字数 127 浏览 12 评论 0原文

有没有办法在活动/服务被杀死之前通知强制关闭请求?

我的意思是当用户点击 Menu > 中的强制关闭按钮时设置>应用领域>>管理应用程序>应用程序名称>强制关闭

Is there a way to notify an activity/service of a force-close request right before it gets killed?

I mean when the user hits the force close button in Menu > Settings > Applications > Manage applications > app name > Force Close.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷路的信 2024-10-02 16:27:40

我认为 ActivityManager 只是终止了托管进程,因此您可能无法获得任何事件/消息/警告。要进行检查,您可以创建一个具有单个 Activity 的应用程序,让您知道是否调用了 onDestroy,以及是否调用了 isFinishing。

Menu > 的路径设置>应用领域>>管理应用程序>应用程序名称>如果有帮助的话,源代码中的强制关闭是:

ManageApplications:
https: //android.googlesource.com/platform/packages/apps/Settings/+/froyo-release/src/com/android/settings/ManageApplications.java

InstalledAppDetails:
https: //android.googlesource.com/platform/packages/apps/Settings/+/froyo-release/src/com/android/settings/InstalledAppDetails.java

ActivityManager.forceStopPackage:
https:// android.googlesource.com/platform/frameworks/base/+/froyo-release/core/java/android/app/ActivityManager.java

ActivityManagerNative.forceStopPackage:
https:// android.googlesource.com/platform/frameworks/base/+/froyo-release/core/java/android/app/ActivityManagerNative.java

一旦它获得本机级别,它就会将其交给一个执行脏工作的服务。再说一遍,我猜它只是停止了这个过程,但这是一个猜测,我不知道本机接口的另一边在源代码中要检查的位置(尽管如果你戳一下它就在那里)周围并想确定)。

此外,您可能想在问题中添加为什么您需要此信息,根据情况,可能会有不同/更好的角度来实现您想要的目标。

I think the ActivityManager just kills the hosting process, so you may not be able to get any event/message/warning. To check you could create an app that has a single Activity that lets you know if onDestroy is called, and further if isFinishing is invoked.

The path to Menu > Settings > Applications > Manage applications > app name > Force Close in the source, in case it helps, is:

ManageApplications:
https://android.googlesource.com/platform/packages/apps/Settings/+/froyo-release/src/com/android/settings/ManageApplications.java

InstalledAppDetails:
https://android.googlesource.com/platform/packages/apps/Settings/+/froyo-release/src/com/android/settings/InstalledAppDetails.java

ActivityManager.forceStopPackage:
https://android.googlesource.com/platform/frameworks/base/+/froyo-release/core/java/android/app/ActivityManager.java

ActivityManagerNative.forceStopPackage:
https://android.googlesource.com/platform/frameworks/base/+/froyo-release/core/java/android/app/ActivityManagerNative.java

Once it gets the native level it hands off to a Service that does the dirty work. Again, I would guess it just stops the process, but that's a guess, and I don't know off the top of my head where the other side of the native interface is in the source to check (though it's there somewhere if you poke around and want to know for sure).

Also you might want to add why you want this information to your question, there might be a different/better angle to getting what you want accomplished, depending on that.

伏妖词 2024-10-02 16:27:40

我对 Android 编程总体来说还很陌生,所以如果这不完全正确,请原谅我。但是,我的理解是,仅当您的应用程序 a) 无响应或 b) 引发了未捕获的异常时,才会显示“应用程序无响应”(ANR) 对话框。

在情况 a) 中,应用程序将无法在合理的时间内响应任何强制关闭通知,因为它已经挂起足以生成 ANR。如果 b) 你的应用程序已经死了。

I'm pretty new here and to Android programming in general, so forgive me if this isn't strictly correct. However, my understanding is that the Application Not Responding (ANR) dialog is only displayed if your application is either a) non-responsive or b) has thrown an exception that was not caught.

In case a) the application will not be able to respond to any force-close notification in a reasonable amount of time since it's already hung up enough to generate the ANR. In case b) your application is already dead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文