如何让我的 Android 应用程序正确终止?

发布于 2024-10-18 05:26:06 字数 233 浏览 5 评论 0原文

我有一个将数据写入 SD 卡的 Android 应用程序。当我通过 USB 电缆连接时,我希望能够从我的电脑上看到这些数据。不幸的是,当我退出应用程序时,它仍处于后台,并且某些系统缓冲区无法正确刷新(或者至少我认为这就是发生的情况)。因此,除非我手动强制应用程序停止,否则我无法正确查看数据。然后,数据就像变魔术一样在 PC 上可见。

我希望程序在退出主要活动时自动终止,或者更好的是我想找到某种方法来刷新系统缓冲区。有人有什么想法吗?

I have an Android application that writes data to the SD card. I want to be able to see this data from my PC, when I connect via a USB cable. Unfortunately the application remains in the background when I quit it, and some system buffers do not get flushed properly (or at least I think that is what happens). As a result I cannot see the data properly, unless I manually force the application to stop. Then the data becomes visible on the PC, as if by magic.

I would like to have the program terminate automatically when I quit the main activity, or better still I would like to find some way to flush the system buffers. Does anyone have any ideas?

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

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

发布评论

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

评论(2

悟红尘 2024-10-25 05:26:06

你关闭你的文件吗?最好的可能是 onPause() 。

检查 http://developer.android.com/guide/topics/fundamentals 中的活动生命周期。 html

编辑:

如果您确实觉得需要终止进程,您可以使用

android.os.Process.killProcess(android.os.Process.myPid());

System.exit(n)

Do you close your file? Best would be in onPause() probably.

Check the activity lifecycle in http://developer.android.com/guide/topics/fundamentals.html

EDIT:

If you really feel you need to kill your process, you can use

android.os.Process.killProcess(android.os.Process.myPid());

or

System.exit(n)
凹づ凸ル 2024-10-25 05:26:06

我真的怀疑这是一个文件刷新问题,您可能没有正确地将数据写入SD卡。让您的应用程序“退出”就像在 onStop 或 onPause 中调用 finish() 一样简单,具体取决于您希望它何时退出。

没有代码,我们无能为力!

I really doubt its a file flush issue, you may not be writing the data to the SD card properly. Getting your application to "exit" is as simple as calling finish() in their onStop or onPause, depending on when you'd like it to quit.

Without code, we can't help!

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