当用户点击子活动中的后退按钮时如何重新加载活动
我有一个活动在 onCreate
方法中启动联系人选择器。当用户选择联系人时,该用户 ID 将传递到新的子活动
。然而,如果用户按下后退键,他们会看到一个空白屏幕,因为 onCreate
似乎没有被再次调用。
我已经尝试过,onRestart
和onResume
,它们解决了后面的问题,但是会发生什么情况,它会调用打开一个的竞争条件在将ID传递给
活动。子活动
之前联系选择器
编辑: 我正在使用 API 2.3.3。
我尝试在子活动中重载 onBack 方法来启动新活动。但是这样做会改变页面渲染的完成方式。当您启动新活动时,新活动从屏幕右侧进入,但是当您回击时,正常实现会导致前一个屏幕从左侧滑入。如果我重载 onBack 来调用新活动,则会发生用户按下后退按钮并且屏幕从屏幕右侧而不是左侧进入的情况。我需要让窗口滑动与默认模式相同。
I have an activity that launches the Contact picker in the onCreate
method. When the user selects a contact, that user's ID gets passed to a new child activity
. If the user presses the back key however, they get presented with a blank screen cause the onCreate
doesn't seem to be getting called again.
I've tried, onRestart
and onResume
, which fix the back issue, but what happens it a race condition in which it will make the call to open up an Contact picker
activity before the ID is passed to the child activity
.
EDIT:
I'm using API 2.3.3.
I've tried the overloading the onBack method in the child activity to launch a new activity. But doing changes how the rendering of the page changes is done. When you launch a new activity the new activity comes in from the right hand side of the screen, but when you hit back the normal implementation causes the previous screen to slide in from the left-hand side. If I overload the onBack to call a new activity, what happens is the user hits the back button and a screen comes in from the right hand side of the screen as opposed to the left. I would need to have the window sliding be the same as the default pattern.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法在按下后退键时调用 onCreate。但是,您可以做一件事来完成联系人选择器活动。重写子活动中的 onBackPressed 函数并在那里启动一个新活动。
You cannot call onCreate on back key pressed. However you can do one thing that finish your contact picker activity. Override the function onBackPressed in Child activity and start a new Activity there.