如何让我的 Android 应用程序正确终止?
我有一个将数据写入 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你关闭你的文件吗?最好的可能是 onPause() 。
检查 http://developer.android.com/guide/topics/fundamentals 中的活动生命周期。 html
编辑:
如果您确实觉得需要终止进程,您可以使用
或
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
or
我真的怀疑这是一个文件刷新问题,您可能没有正确地将数据写入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!