0

Situation

In my alarm clock app I start a NewAlarmActivity by clicking a button. After the user has made all the selections, alarm gets set and `finish() is called.

The matter

I create a new LinearLayout object with images and text within it. 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. Somehow I have to pass that LinearLayout object to the first activity and tell it to receive and add the object to the screen.

How can I do that?

shkschneider
  • 17,833
  • 13
  • 59
  • 112
Droidman
  • 11,485
  • 17
  • 93
  • 141

2 Answers2

2

You just need to read some documentation about startActivityForResult().

BTW, IMHO, you should not transport your LinearLayout object between activities, that's ugly.

How to manage `startActivityForResult` on Android?

Starting Activity And Getting Result

This has been asked countless times...

Community
  • 1
  • 1
shkschneider
  • 17,833
  • 13
  • 59
  • 112
  • just one question: the putExtra() method won't accept a LinearLayout object as parameter. How to solve that? – Droidman Oct 31 '12 at 08:34
  • You should not transport the `LinearLayout` but data that will allow the second view to build that `LinearLayout` itself. – shkschneider Oct 31 '12 at 09:22
1

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.

JoxTraex
  • 13,423
  • 6
  • 32
  • 45
  • any tutorials or examples please..? never did it before – Droidman Oct 30 '12 at 14:14
  • Just look up databases and creating views dynamically and you should be good. – JoxTraex Oct 30 '12 at 16:53
  • No need to go through a database unless you want this setting to be persisted. Just use a singleton do it all in memory. – dnkoutso Oct 31 '12 at 05:49
  • I dont know if using memory is the best option @dnkoutso ... According to the sound of his Activity, it sounds like a Settings Activity, which ideally is persisting this data somewhere, might as well use the persisted data instead of using memory imho. – JoxTraex Oct 31 '12 at 06:10
  • You are right, I use a PreferenceActivity to set up an alarm. The thing is when the user is done, a broadcast is sent to the corresponding Receiver and (how I planned it) a new LinearLayout ist created according to user's infromation. Now the same activity must be ready to use to set up an another alarm – Droidman Oct 31 '12 at 07:59
  • Build your new View according to the data in the database, best way to do it. – JoxTraex Oct 31 '12 at 17:38