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
 http://developer.android.com/guide/topics/manifest/activity-element.html #config

  android:configChanges
< http://developer.android.com/guide/topics/manifest/activity-element.html #config>=["mcc",
"mnc", "locale",
                                 "touchscreen", "keyboard", "keyboardHidden",
                                 "navigation", "orientation", "screenLayout",
                                 "fontScale", "uiMode"]



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







-- 
*Farah Hanif*
613-851-9128

-- 


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




 http://developer.android.com/reference/android/app/Activity.html #ConfigurationChanges


-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/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 < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 



Other Threads

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

Hi,

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);
        parameters.setPictureFormat(PixelFormat.JPEG);
        parameters.setPreviewFormat(PixelFormat.JPEG);
        mCamera.setParameters(parameters);
      }

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

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

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

                break;
            }
        }

public boolean WriteToFile(byte[] fileBArray)
    {
        boolean result = false;
        try
        {
            FileOutputStream fos = new FileOutputStream(path);
            fos.write(fileBArray);
            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?

Thanks!

Niko



-- 
http://mypetprojects.blogspot.com/

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

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?

Clive

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

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?