向尚未开始的活动发送消息
在我的应用程序中,我使用按钮
startActivity( new Intent(getBaseContext(),Register.class));
从主 Activity 启动 Register 活动。此 Register 活动创建可以在 ListActivity 中查看的记录。
如果我从主活动(使用另一个按钮)转到 ListActivity 并决定将记录的数据从 ListActivity 发送到 Register 活动以对其进行编辑,则有两种可能性:
1- Register 活动从未被调用过
2- Register 活动在后台打开
我有两个问题:
- 从 Main 调用 startActivity Register.class 一次,从 ListActivity 调用一次,它会生成 Register 的两份副本还是一份?
- 当我从 ListActivity 调用 Register 活动并尝试使用处理程序传递数据时,处理程序消息在活动打开之前到达,并且数据未显示在 Register 屏幕中?我怎样才能做到这一点?有没有办法从ListActivity中知道Register的视图何时打开?
谢谢。 查尔斯.
In my application I start a Register activity from the Main Activity with a button
startActivity( new Intent(getBaseContext(),Register.class));
This Register activity creates records that can be viewed in a ListActivity.
If I go to the ListActivity from the Main Activity (with another button) and decide that I want to send the data of a record from the ListActivity to the Register activity in order to edit it, there are two possibilities:
1- the Register activity has never been called
2- the Register activity is opened in the background
I have two questions:
-Calling startActivity Register.class once from Main and once from ListActivity will it make two copies of Register or one?
-When I call Register activity from ListActivity and try to pass data with a handler, the handler message arrives before the activity is opened and the data do not show in the Register screen? How can I do that? Is there a way to know from the ListActivity when the view of Register is opened?
Thanks.
Charles.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个问题有一个复杂的答案,但很快您就可以控制活动的实例化,只是它对用户交互流程有影响:请参阅 活动和任务,特别是启动模式。
对于第二个,我不知道你要传递什么类型的数据,但请考虑将其放入意图中一些 Intent.putExtra() 方法(有很多多种数据类型)。
The first question has a complex answer, but shortly you can control instantiation of activities, only it has implications in flow of user interaction: see Activities and Tasks, particularly Launch modes.
For the second, I don't know what kind of data you're going to pass, but consider putting it in the intent with some Intent.putExtra() method (there are many for many types of data).