Assistance with understanding LunarLander code

by steve_macleod » Fri, 12 Dec 2008 23:49:25 GMT


Sponsored Links
 Hi,
I have been working through the lunarlander example application, in
an
attempt to understand the source code. I have run into a couple of
problems, and would really appreciate if someone could space a couple
of minutes to assist in may understanding.

The onCreate method contains the following:


   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        // turn off the window's title bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);


        // tell system to use the layout defined in our XML file
        setContentView(R.layout.lunar_layout);


        // get handles to the LunarView from XML, and its LunarThread
        mLunarView = (LunarView) findViewById(R.id.lunar);
        mLunarThread = mLunarView.getThread();


        // give the LunarView a handle to the TextView used for
messages
        mLunarView.setTextView((TextView) findViewById(R.id.text));


        if (savedInstanceState == null) {
            // we were just launched: set up a new game
            mLunarThread.setState(LunarThread.STATE_READY);
            Log.w(this.getClass().getName(), "SIS is null");
        } else {
            // we are being restored: resume a previous game
            mLunarThread.restoreState(savedInstanceState);
            Log.w(this.getClass().getName(), "SIS is nonnull");
        }
    }


I can see that we are performing the following:
        Turn off the title bar in the window
        Set the activity content to the lunar_layour layout file
        gets a reference to the 'lunar' layout
        gets a reference to the thread member of the LunarView class
        give the LunarView a reference to the textview for game
messages
        we then set the state of the lunar thread to STATE_READY,
which also
outputs a bunch of status messages


The problem is that after executution of setState, the code seems to
end. I can see no sections of code that actually creates the
LunarView
or LunarThread objects, which are required to start the game proper.
Obviously I am missing something here, I was wondering if anyone
could
assist! Thanks lots!


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



Assistance with understanding LunarLander code

by RichardS » Sat, 13 Dec 2008 01:19:55 GMT


 Steve,

This is my understanding of it:

The file res/layout/lunar_layout.xml describes the layout of the view.
The src/R.java file is auto generated: it equates object ids to names.

setContentView(R.layout.lunar_layout)

'reads'  lunar_layout.xml file and creates and instance of the
LunarView class and hence the View itself.
If you look in the XML file it contains an Id string "@+id/lunar":
this is one of the ids that R.java
defines a name for - in this case R.id.lunar.

mLunarView = (LunarView) findViewById(R.id.lunar)

searches all view for the one identified by R.id.lunar ( == "@+id/
lunar").  This returns a reference to
the LunaView instance created above which we store in a member
variable.

The constructor for LunarView created a private LunarThread object so
doing:

mLunarThread = mLunarView.getThread()

enables us to retrieve a reference to the thread object.


Hope that's correct and helpful!

richard.






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


Sponsored Links


Assistance with understanding LunarLander code

by steve_macleod » Sat, 13 Dec 2008 22:04:59 GMT


 i Richard,
OK, so it looks like the line:

mLunarView = (LunarView) findViewById(R.id.lunar)

creates an instance of the LunarView object, running the constructor.
I didnt think that running the findViewById and casting to a LunarView
would have this effect.

Thanks for that

On Dec 12, 5:19pm, RichardS <richardswingw...@googlemail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Assistance with understanding LunarLander code

by steve_macleod » Sat, 13 Dec 2008 22:57:42 GMT


 i,
At what point does the surfaceCreated() method fire? I presume its
after we add the callback interface with addCallback?



On Dec 12, 5:19pm, RichardS <richardswingw...@googlemail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Assistance with understanding LunarLander code

by RichardS » Sat, 13 Dec 2008 23:51:56 GMT


 teve, I'm sure the instance is created by

setContentView(R.layout.lunar_layout)

so the constructor will have been run by the time we do

mLunarView = (LunarView) findViewById(R.id.lunar)


richard.

On 13 Dec, 14:04, steve_macleod <steven_macl...@hotmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Assistance with understanding LunarLander code

by Mark Murphy » Sat, 13 Dec 2008 23:58:06 GMT


 


Correct.

If you look in res/layout/lunar_layout.xml, you will see the declaration:

<com.example.android.lunarlander.LunarView
       android:id="@+id/lunar"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"/>

When the layout is inflated via setContentView(), the constructors for 
each widget and container are called. For built-in widgets like 
FrameLayout, Android knows they are in the package android.widget; for 
custom ones, the full namespace is spelled out in the layout 
(com.example.android.lunarlander.LunarView).

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 1.9 Available!

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



Assistance with understanding LunarLander code

by steve_macleod » Sun, 14 Dec 2008 01:06:30 GMT


 Cheers, that makes sense. I didnt notice the reference to the class in
the lunar_layour xml.





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



Assistance with understanding LunarLander code

by Ralf » Mon, 15 Dec 2008 00:59:41 GMT


 o actually what you describe is done by the setContentView() call. It
takes the XML layout and inflates (==creates) the associated view
instances in memory.

Then findViewById() is able to give you the view instance given its XML id.

HTH
R/

On Sat, Dec 13, 2008 at 6:04 AM, steve_macleod
<steven_macl...@hotmail.com> wrote:

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



Other Threads

1. OOT Pamer Polo shirt Official id-android

hiks... :( hiks...
sayang sekali saya telat mesen.... [mana g akan dibuat lagi...] hiks......
*ngiri nih...
model-nya bagus... om, qr code apakah itu?

On 30 July 2010 08:47, Lutfi Hidayat Ramdhani <



> 

2. alsa in eclair ,mediaserver can't start

Hi,everyone
I now want to porting alsa to eclair.My board are smdk6410,the audio
module are  wm8987.
these are my steps:
1.download the snapshot  of eclair version from android.git.kernel.org/
platform/external
and then tar them to external/
2.
build/target/board/.../BoardConfig.mk

#HAVE_HTC_AUDIO_DRIVER := true
BOARD_USES_GENERIC_AUDIO :=false
BOARD_USES_ALSA_AUDIO := true
BUILD_WITH_ALSA_UTILS := true

3.make and add sth to init.rc
# for alsa sound
     chown audio audio  /dev/snd/controlC0
     chown audio audio  /dev/snd/pcmC0D0c
     chown audio audio  /dev/snd/pcmC0D0p
     chown audio audio  /dev/snd/timer
     chown audio audio  /dev/snd/audio
     chown audio audio  /dev/snd/dsp
     chown audio audio  /dev/snd/mixer
     chown audio audio  /dev/snd/seq
     chown audio audio  /dev/snd/
     chmod 0666  /dev/snd/controlC0
     chmod 0666  /dev/snd/pcmC0D0c
     chmod 0666  /dev/snd/pcmC0D0p
     chmod 0666  /dev/snd/timer
     chmod 0666  /dev/snd/audio
     chmod 0666  /dev/snd/dsp
     chmod 0666  /dev/snd/mixer
     chmod 0666  /dev/snd/seq


4.add asound.conf to system/etc/asound.conf

then I boot the system ,but the system can't bootup now!(before
porting the alsa,it can bootup)
I can see the log from the std output:
# init: untracked pid 901 exited
# init: untracked pid 991 exited
# init: untracked pid 1079 exited
and I  found that the print pids are the pids of /system/bin/
mediaserver
and here are the logcat related alsa:(no error )
  330 D/AudioHardwareALSA(  687): openOutputStream called for devices:
0x00000002
 331 D/ALSAModule(  687): open called for devices 00000002 in mode
0...
 574 I/ALSAModule(  687): Initialized ALSA PLAYBACK device
AndroidPlayback_Speaker_normal
 615 I/AudioFlinger(  687): AudioFlinger's thread 0x32520 ready to run
 616 D/ALSAModule(  687): route called for devices 00000002 in mode
0...
3949 D/AudioHardwareALSA(  816): openOutputStream called for devices:
0x00000002
3950 D/ALSAModule(  816): open called for devices 00000002 in mode
0...

If I comment the mediaserver in init.rc ,the system still can not boot
up
the logcat are:
4011 I/ServiceManager(  704): Waiting for sevice media.audio_policy...
4012 I/ServiceManager(  704): Waiting for sevice media.audio_policy...
4013 W/AudioSystem(  704): AudioPolicyService not published,
waiting...
4014 I/ServiceManager(  704): Waiting for sevice media.audio_policy...
4015 I/ServiceManager(  704): Waiting for sevice media.audio_policy...

then I try to start it manually and use strace to log it
strace  -o /mediaserver-log mediaserver
and the failure-cause-maybe  in /mediaserver-log   are:
1393 open("/dev/snd/pcmC0D0p", O_RDWR|O_NONBLOCK|O_ASYNC|O_LARGEFILE)
= 11
1394 close(10)                               = 0
1395 ioctl(11, AGPIOC_ACQUIRE or APM_IOC_STANDBY, 0xbeb646e0) = 0
1396 fcntl64(11, F_GETFL)                    = 0x22802 (flags O_RDWR|
O_NONBLOCK|O_ASYNC|O_LARGEFILE)
1397 ioctl(11, AGPIOC_INFO, 0xbeb646dc)      = 0
1398 ioctl(11, AGPIOC_RELEASE or APM_IOC_SUSPEND, 0xbeb646d4) = 0
1399 mmap2(NULL, 4096, PROT_READ, MAP_SHARED, 11, 0x80000) = -1 ENXIO
(No such device or address)

It seem that mmap2() are the cause .but I don't know what to do now

also ,when run strace  -o /mediaserver-log mediaserver
the std output are:
ptrace: umoven: I/O error
ptrace: umoven: I/O error
ptrace: umoven: I/O error
ptrace: umoven: I/O error
ptrace: umoven: I/O error
ptrace: umoven: I/O error
....
 So could you help me?
Thanks
--Weber


-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. Multiple Back Button clicks needed to exit application

4. Unable to start NetlinkHandler

5. Compiling Android Source Code, error

6. How to delete the text messages based on the senders' number?

7. Switch to SGS: Which one is yours?