views:

76

answers:

1

It would be nice if StackOverflow had a section where we could post tutorials like mine so that I can answer literally hundreds of questions that have been asked here with a single blow. See... every day I read questions about how to pass complex objects between activities, how to save state so that your app can resume after orientation change, how to update listviews when the data changes, etc, etc.

Here is the second part of a tutorial series I posted on my blog... I hope that you actually read it... because I haven't seen any examples like it anywhere... and it has changed how I think about developing for Android across the board. The question is... is there a downside or negative affect of developing like this?

Beyond Smart Lists – How Observable Singletons change the game.

Please read through both of these tutorials carefully... I will answer any questions about it here that I can... I really want to know what you think about this and if it might solve issues for you.

NOTE TO MODERATORS: there are no advertisements of any kind on my blog.. so don't just close this because you think I am spamming somehow... I am not going to duplicate my post here. And... really I want to know if there is a flaw in this approach.

+2  A: 

Have you read about Android's Application class?

Macarse
Yes, I have actually. There is a great tutorial about how to use it at http://www.heikkitoivonen.net/blog/2010/05/13/bacon-rank-android-app-details/ but it's not really the same approach... is it as flexible? In addition, the way these Observable objects work is that they post updates to any consuming Activity anytime their properties change... This does, however, bring up an important issue I hadn't considered. What happens if an Observer is no longer active... I am not sure if the Observable will throw an exception or not if it tries to update an Observer that doesn't exist.
androidworkz
Ok... I just ran a test and it appears that attempts to update null observers don't cause any side effetcs but it probably makes sense to call observable.deleteObserver(this) in the onDestroy() and onPause() and restore the object and Observer in onResume() or onRestoreInstanceState()
androidworkz
It is fundamental to the Observer patter that the Observer remove itself from everything it is observing when it is no longer required. In garbage-collected environments the Observer still exists as long as there is a reference to it in the Observables. Your observers should remove themselves from all their Observables when they become inactive.
DJClayworth
yep... I have actually been doing that because I did see that it was leaking memory when I didn't.
androidworkz