Sharing Objects between activities using Singleton ?

by kungfuslippers » Tue, 28 Apr 2009 22:36:01 GMT


Sponsored Links
 Hi,

I have an application with N Activities that all need access to an
'engine' class.

I've seen discussion that says that I'd have to implement the Engine
using a Singleton pattern to allow the different activities to access
the engine.

Is this is the only/best/recommended way to do it in the Android
paradigm?

Are there alternatives - just out of interest.




--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Attachment html ga bisa dibuka

Para suhu minta tolong dong kenapa ya di N1 ane file attachment html ga bisa
dibuka



"Dikirim dengan Nexus One dari Putussibau perbatasan Indonesia-Malaysia
(Powered by M2 Net INDOSAT)"

-- 
"Indonesian Android Community [id-android]" 

2. onActivityResult not being called in Activity that uses GLSurfaceView

Help!

I have an activity that, instead of getting a response back from a
startActivityForResult, is destroyed (with no callbacks) when the
responding activity finishes!

The activity (call it GL) subclasses Activity and sets its contentView
 to be a GLSurfaceView. This Activity overlays a MapView and uses
translucency to draw OpenGL objects over the Map.


Here are the details:
The  app that uses Intents for a menu system.

An activity needing a menu does:

...startActivityForResult(intent, 0)

to fire off the menu (a ListView).

When the menu item is selected, the menu sets a result with:

........setResult(Activity.RESULT_OK, intent); menuActivity.finish();

In the originating activity, the onActivityResult  should be called
with the results.

I have two activities - one where that works, one where it doesn't.
Both use the same common method to do the setActivityForResult call.

The first a MapActivity which is also the starting activity of my app.
It has no problem using the menu system to get results.

The second is the GL Activity, an Activity which sets it content to be
a GLSurfaceView.

This activity never sees onActivityResult after it sends the menu
intent, and it also vanishes without a trace (no lifecycle methods
called other than suspend()).


So the flow is like this:

MapView  ---- intent ---> MenuActivity
                                   displays list of choices
                                   receives a click on a choice
                                   sets a response
                                   calls finish()
mapview.onActivityResult <-- called with result

mapview --- intent --->    Activity using GLSurfaceView
                                   renders shape
                                   gets a click
                                   sends an intent ---intent-----
                                   onSuspend called
displays list of choices
 
receives a click on a choice
 
sets a response
 
calls finish()
                        surfaceview activity vanishes <----
unexplained magic --------

Something odd is going on here!

Any ideas?


-- 

3. Change Button Position Screen

4. dependency between applications

5. Aren't focus states supposed to bubble to child Views?

6. Will 900ms of calcs run faster in another thread?

7. Help with Emulator Testing