Why are onCreate() onStart() etc. called when handset orientation is changed?

by steff » Wed, 16 Dec 2009 02:20:17 GMT

Sponsored Links
 Hi everyone,

I got my hands on Android which is really fun. But at some point I
don't seem to understand the concept. I've got a Main class which
reads like this:

public class Main extends Activity implements SensorEventListener
{ ... }

in the onCreate(...)  I set the layout to
and add an OnTouchEvent Listener to the sole View in main.xml:
myView.setOnTouchListener(new OnTouchListener() {
                        public boolean onTouch(View v, MotionEvent event) {...

As you can see I also implemented a SensorEventListener which is used
if required. All works fine so far.

But my problem is this (at this point my misunderstanding kicks in):
whenever I rotate the device the onCreate(), onStart() etc. methods
are called, causing my app to act as if it just started. Furthermore,
I feel unable to implement an onSizeChanged(int w, int h, int oldw,
int oldh) { ... } Listener.

Can anyone please explain where my error in reasoning is? I am working
on a tiny app which is more or less done, except for the just
mentioned bug(s). Maybe I got it all wrong but it does what it is
supposed to do (i.e. sending touch positions and accelerometer data
over the network via UDP).

Thanks for any help.


Other Threads

1. Minta testimoni bp rudi

Atas seijin beliau saya minta testimoni bp rudi dengan :
Email : rudipriba...@gmail.com
Hp : 081***0873

Ma kasih


Powered by Telkomsel BlackBerry

"Indonesian Android Community [id-android]"

PING'S mobile
Email: sa...@pings-mobile.com  Ph. (021) 96087100
Yopie Ratjoen
Email: yo...@ratjoen.com  Ph. 08977726681
Gila original
Email: i...@gilaoriginal.com  Ph. (031) 91555898

Aturan Jual/Kloteran ID-Android  http://goo.gl/azW7

2. Controlling a service

Hi all, I am (still) quite confused about services.

What I need is to perform some network operations in background inside
a service. I want them to run in a service because, as pointed out in
the "developing rest client application" talk from google io, I don't
want to loose the result if the activity is brought in background.

What sounds quite obvious is to use an Intent Service, and get the
result as a broadcast. In this way I am sure the service will die and
no consume any other resources when its done, but I need to convert
the actions I want to perform to intents and back.

Well, I was now wondering if it makes sense to bind to the service
instead, at least for getting the result.

And a more general question: is the bind mechanism suitable for one
shot services, or it just make sense for persistent services?

What happens if I call the startService method but the service is
already active? Will it start another service, or will it call the
onStartCommand of the same service? I am asking this because if I use
"regular" non sticky service, it could happen that I need it to
perform some action and I don't know if it is already active (and I
don't want to have a queue of action waiting for onServiceConnected to
be called.

Hope I was clear enough, it's pretty late here :-)

Thanks in advance,



3. Strange network behavior with two phones

4. Evaluate javascript value on WebView, Android

5. How are credentials stored in the OS framework?

6. ExtandableLists and LongClicks

7. Getting ready to Publish