简体   繁体   English

将对象传递到另一个活动

[英]passing objects to another activity

Situation 情况

In my alarm clock app I start a NewAlarmActivity by clicking a button. 在我的闹钟应用程序中,我通过单击一个按钮来启动NewAlarmActivity After the user has made all the selections, alarm gets set and `finish() is called. 用户做出所有选择之后,将设置警报并调用`finish()。

The matter 这件事

I create a new LinearLayout object with images and text within it. 我创建一个新的LinearLayout对象,其中包含图像和文本。 That layout must be added to the screen of previous activity (to another LinearLayout placed inside a ScrollView ) so the user is able to see the alarm set. 该布局必须添加到上一个活动的屏幕上(放置在ScrollView内的另一个LinearLayout ),以便用户能够看到警报集。 Somehow I have to pass that LinearLayout object to the first activity and tell it to receive and add the object to the screen. 我必须以某种方式将那个LinearLayout对象传递给第一个活动,并告诉它接收该对象并将其添加到屏幕。

How can I do that? 我怎样才能做到这一点?

You just need to read some documentation about startActivityForResult() . 您只需要阅读一些有关startActivityForResult()文档。

BTW, IMHO, you should not transport your LinearLayout object between activities, that's ugly. 顺便说一句,恕我直言,您不应该在活动之间传输LinearLayout对象,这很丑陋。

How to manage `startActivityForResult` on Android? 如何在Android上管理`startActivityForResult`?

Starting Activity And Getting Result 开始活动并获得结果

This has been asked countless times... 这已经被问过无数次了...

No You don't have to do this. 不,您不必这样做。 Try the approach of storing your data into a database and then when going into that Activity, build your layout according to the data you have. 尝试将数据存储到数据库中的方法,然后在进入该活动时,根据您拥有的数据构建布局。 This is a much better way than passing a layout from one Activity to antoher. 与将布局从一个活动传递到另一个活动相比,这是一种更好的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM