Android 中的返回按钮?

发布于 2024-12-02 07:28:00 字数 296 浏览 0 评论 0原文

我有一个问题。可以重写 Android 应用程序上的 onBackPressed 方法吗? 在我的 Android 应用程序中,我使用 Android 相机设备拍照。之后,用户可以查看照片,如果他喜欢它,他可以将其提交到摄影比赛。如果他不喜欢它,他可以重新拍摄照片。 问题出在 Android 设备的 后退按钮 上。当用户查看照片并按后退按钮时,他可以看到上一张拍摄的照片。我不希望这样!!!照片是保存在 SDcard 上。拍摄一张照片后,前一张照片就会被新照片替换...并且仍然按回键,我可以看到之前的照片。有什么想法吗?

I have a question. Is it ok to override the onBackPressed method on Android app?
In my android app I take photos using the android camera device.After that the user can see view the photo and if he likes it he can submit it to a photo contest.If he doesn't like it he can retake the photo.
The problem is with the backbutton of the android device.When the user views the photo and press the back button he can see the previous photo taken.And I don't want that!!!the photos are saved on SDcard.And once a photo is taken the previous one ie replaced by the new one...and still by pressing back I can see the prevois photo.Any idea

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

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

发布评论

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

评论(4

沧桑㈠ 2024-12-09 07:28:00

如果您在活动的其他部分不需要后退按钮,则可以覆盖它。

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {   
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

If you don t need your backbutton in other part of your activity, it is ok to override it.

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {   
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
镜花水月 2024-12-09 07:28:00

是的,覆盖后退按钮和其他按钮被认为是可以的。

您可以在这里阅读一篇关于它的好文章:
http://android-developers .blogspot.com/2009/12/back-and-other-hard-keys- Three-stories.html

Yes it is considered ok to override the back button, and other buttons.

You can read a good article about it here:
http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html

冷心人i 2024-12-09 07:28:00

当心。您需要确保流程对用户来说是直观的,但是您可以更改流程。

阅读此页面,其中涵盖了可用于操纵其工作方式的各种选项
http://developer.android.com/guide/practices/ui_guidelines/activity_task_design.html

Be careful. You need to make sure the process flow is intuitive to the user, but yes you can change the flow.

Read this page which covers various options available for manipulating how it works
http://developer.android.com/guide/practices/ui_guidelines/activity_task_design.html

屋顶上的小猫咪 2024-12-09 07:28:00

应用程序流程对我来说不是很清楚,但听起来您可以通过两种不同的方式解决问题。
首先是重写 onBackPressed 方法。但是,您确实必须考虑用户如何在不使用主页按钮的情况下退出应用程序。
第二个选项是不在活动堆栈中存储活动,请参阅此处

The application flow isn't very clear to me, but it sounds like you can fix the problem in two seperate ways.
First is to override the onBackPressed method. But then you really have to think about how the user can get out of the application while not using the home button.
Second option is to not store the activity in the activity stack, see here

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