App restarts when screen is rotated

by Digeridoo » Wed, 27 Apr 2011 04:53:13 GMT

Sponsored Links
 Hi All,

My game app resets to start position when I rotate the phone from
portrait to landscape or the other way round. Do I need to disable the
gravity sensor and do I do this in the OnCreate method?


Re: App restarts when screen is rotated

by Farah Hanif » Wed, 27 Apr 2011 04:58:15 GMT

 You need to get configChanges of your activity to "orientation".  This means
that app will handle all the orientation changes by itself.

See #config

< #config>=["mcc",
"mnc", "locale",
                                 "touchscreen", "keyboard", "keyboardHidden",
                                 "navigation", "orientation", "screenLayout",
                                 "fontScale", "uiMode"]

On Tue, Apr 26, 2011 at 4:53 PM, Digeridoo

*Farah Hanif*


Sponsored Links

Re: App restarts when screen is rotated

by lbendlin » Wed, 27 Apr 2011 04:58:51 GMT

 Activities are destroyed and recreated by default when the orientation 
changes. If you don't like that you can use various methods to either 
prevent that from happening (by handling orientation changes yourself) or to 
restore the state of the activity. 


Re: App restarts when screen is rotated

by TreKing » Wed, 27 Apr 2011 05:31:36 GMT

 On Tue, Apr 26, 2011 at 3:53 PM, Digeridoo #ConfigurationChanges

TreKing <> ; - Chicago
transit tracking app for Android-powered devices


Re: App restarts when screen is rotated

by Indicator Veritatis » Wed, 27 Apr 2011 06:25:36 GMT

 Of the two approaches lbendlin mentions, the latter is more commonly
recommended. I used to know why.


Re: Re: App restarts when screen is rotated

by TreKing » Wed, 27 Apr 2011 06:30:36 GMT


Because your app can be killed and recreated by other means - like when the
user presses Home and does other things for a while. If you properly handle
saving and restoring instance state, you'll survive this case as well. If
you only handle the config changes, then you will fail this case and a user
coming back to your game will have to start over.

TreKing <> ; - Chicago
transit tracking app for Android-powered devices


Other Threads

1. How to save a preview frame as a JPG image


I have successfully created a video preview and I would like to save a
preview frame as a JPG image.

The camera parameters are set by calling the following method:

private void setCameraParameters() {
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setPreviewSize(mScreenResolution.x, mScreenResolution.y);

and these are the methods that handle the data from the camera:

public void onPreviewFrame(byte[] data, Camera camera) {
            if(mPreviewHandler != null)
                Message message =
                    mScreenResolution.x, mScreenResolution.y, data);

public void handleMessage(Message msg)
            case MSG_FRAME_REFRESHED:
                  String path = "JPGFrame" + frameCount;
                  fileRW.WriteToFile((byte[]) msg.obj);


public boolean WriteToFile(byte[] fileBArray)
        boolean result = false;
            FileOutputStream fos = new FileOutputStream(path);
            result = true;
        catch(Exception e)

        return result;

The methods have been pasted from different classes. First the camera
parameters are set. Then on every frame refresh onPreviewFrame() is executed
and sends a message with camera's data. The message is handled by
handleMessage(Message msg) method. Finally from the handleMessage()
WriteToFile() is called.

Does anyone know what could be wrong here or how to save preview frames as
JPG images?





2. Syncing contacts direct to pc

Hi all,

I would like to sync my contacts directly to my pc without going
through gmail/cloud solution. Anyone know how I could do this?



3. Android porting on beagle board

4. Desktop,laptop computers and cameras

5. Problem calling openStream() FileNotFoundException

6. Desktop,laptop computers and camera's

7. how to create custom button and add a click listener?