views:

308

answers:

1

I have three classes one main-activity(named MainMap), one non-activity class(named MyItemizedOverlay), and one activity class(named AudioStream). I want to start AudioStream activity from non-activity class but i don't know how to. i tried this is in third class(called MyItemizedOverlay):

            Intent myIntentA = new Intent(MainMap.this, AudioStream.class);
            myIntentA.putExtra(AUDIO_STREAM,AUDIO_STREAM_URL);
            MojProg.this.startActivity(myIntentA);

but it doesn't work, says: No enclosing instance of the type MainMap is accessible in scope

What should i do? What shoul i write instead of MainMap.this?

+1  A: 

Hi Nikola,

This isn't so much an Android question as it is a Java question. Unless you were to make "MyItemizedOverlay" an inner class of "MainMap" (see http://forums.sun.com/thread.jspa?threadID=690545), what you really need is for MyItemizedOverlay to store an internal reference to the MainMap object that it wants to use for the inent.

Regards, Mark

Mark
Thanks Markto store an internal reference to the MainMap object that it wants to use for the inent? can you give me an example on how to do that?
Nikola
Typically you would do this by passing in the MainMap reference as a parameter to the MyItemizedOverlay constructor and then storing it in a data member inside the MyItemizedOverlay object. If you use this approach, however, you'll need to handle the MainMap being "torn down" and rebuilt via the onSaveInstanceState and onRestoreInstanceState methods in order to maintain a valid current reference.
Mark