3

Possible Duplicate:
Android: Temporarily disable orientation changes in an Activity

Me testing in Samsung Galaxy tab. In that i have made two layout folder for both ORIENTATION_LANDSCAPE and ORIENTATION_PORTRAIT with specific layout xml in it.
In that layout i have a button and on clicking it start a progress dialog (doing some stuff using AsyncTask, after that going to new intent)
But when the device is rotated when the progress dialog is working, that dialog and AsyncTask stop and new layout is loaded. If i understood correctly, I think the onCreate is called when device is rotated How i can block calling onCreate while rotating device when My AsyncTask start?
IN SHOT
How i can lock Orientation of a device by code, for example Lock Orientation on a button click
Thank you

Community
  • 1
  • 1
Labeeb Panampullan
  • 34,521
  • 28
  • 94
  • 112

4 Answers4

6

Refer this url , in that they clearly explained to do this

http://eigo.co.uk/News-Article.aspx?NewsArticleID=103

Sankar Ganesh PMP
  • 11,927
  • 11
  • 57
  • 90
2

There's an absolutely great answer from CommonsWare regarding How to manage orientation changes with a progressdialog.

Community
  • 1
  • 1
Kevin Gaudin
  • 9,927
  • 3
  • 32
  • 34
0

It isn't possible to 'block' onCreate in the way you're describing. Whenever there's a configuration change, the current activity is destroyed and recreated so onCreate() will always be called.

You might want to look at onRetainNonConfigurationInstance() however - it can allow storing an AsyncTask.

Squonk
  • 48,735
  • 19
  • 103
  • 135
0

Like MisterSquonk said. There is no way of blocking the call to onCreate(). You can either block the rotation and force your application to a certain orientation or you have to inform all parts of your application that your activity is restarting.

To force a certain orientation for you application take a look at this answer.

Community
  • 1
  • 1
Octavian Helm
  • 39,405
  • 19
  • 98
  • 102