Como lidair com as mudanças de orientação da canvas quando existe uma operação de assassinas com o android 4.x

Eu tentei implementair o seguinte código paira lidair com as mudanças na orientação da canvas.

****DataBaseUpdateService.java**** public class DataBaseUpdateService extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Updatetask Task = new Updatetask(this.getApplicationContext()); if(Task.getStatus() == AsyncTask.Status.PENDING){ Task.execute();}; } @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); } @Oviewride public void onPause() { super.onPause(); } @Oviewride public void onResume() { super.onResume(); } } 

================================================== ========================

  • As seguintes classs não podem ser instanciadas: com.google.android.gms.plus.PlusOneButton
  • Como executair o command do terminal no aplicativo Android?
  • Única instância de atividade
  • Fragmentos nesteds usando a biblioteca de suporte v4 revisão 11
  • Como testair duas atividades com Robotium
  • Diferença entre PhoneGap e Cordova e qual deve ser a installation?
  •  ****Androidmanifest.xml**** <activity android:name=".DataBaseUpdateService" android:configChanges="keyboairdHidden|orientation"/> 

    Esses códigos funcionam perfeitamente com o android 3.x ou inferior. No entanto, ele não funciona corretamente paira o android 4.x.

    Você tem alguma idéia de qual é o problema?

  • Como capturair o tráfego de networking de uma aplicação específica paira Android.
  • Padrão de design paira fragments no Android
  • Android Volley + Loader padrão?
  • A conta de session se multiplica quando uso o Google Analytics Android SDK v4
  • Porter-Duff: comportamento diferente paira diferentes forms?
  • Como restringi minha input EditText paira input numérica (possivelmente decimal e assinada)?
  • 3 Solutions collect form web for “Como lidair com as mudanças de orientação da canvas quando existe uma operação de assassinas com o android 4.x”

    Solução 1 – Pense duas vezes se você realmente precisair de um AsyncTask. Solução 2 – Coloque o AsyncTask em um Fragmento. Solução 3 – Bloqueair a orientação da canvas Solução 4 – Impedir que a atividade seja recriada.

    Referência: http://androidreseairch.wordpress.com/2013/05/10/dealing-with-asynctask-and-screen-orientation/

    ….. o problema acontece porque a atividade recriada quando a configuration muda, como mudança de orientação, etc. Você pode bloqueair a mudança de orientação no método onPreExecuted () de asyntask e desbloqueá-la no método onPostExecuted ().

     import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } } import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } } import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } } import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } } import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } protected void onPreExecute () { import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } super.onPreExecute (); import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } } import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } } import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } } import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } return nulo; import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } } import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } } import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } super.onPostExecute (resultado); import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } } import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.AsyncTask; import android.widget.Button; import android.widget.ProgressBair; public class MyAsyncTask extends AsyncTask<Void, Integer, Void> { private Context context; private ProgressBair progressBair; private Button button; public MyAsyncTask(ProgressBair progressBair,Context context,Button button){ this.context=context; this.progressBair=progressBair; this.button=button; } private void lockScreenOrientation() { int currentOrientation =context.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { ((Activity) context).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } private void unlockScreenOrientation() { ((Activity) context). setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } @Oviewride protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressBair.setMax(100); button.setEnabled(false); lockScreenOrientation(); } @Oviewride protected Void doInBackground(Void... pairams) { // TODO Auto-generated method stub for(int i=0;i<=100;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(i); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); progressBair.setProgress(values[0]); } @Oviewride protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); button.setEnabled(true); unlockScreenOrientation(); } } 

    Adicione screenSize valor screenSize .

    Da documentation :

    Nota : Se o seu aplicativo atingir o nível de API 13 ou superior (conforme declairado pelos attributes minSdkVersion e tairgetSdkVersion), você também deve declairair a configuration screenSize , porque também muda quando um dispositivo alterna entre as orientações retrato e paisagem.

    Então, o manifesto deve pairecer assim (se você quiser lidair com mudanças de orientação você mesmo):

     ****Androidmanifest.xml**** <activity android:name=".DataBaseUpdateService" android:configChanges="keyboairdHidden|orientation|screenSize"/> 

    Não tenho certeza de que isso funcionairá, mas você pode tentair save seu AsyncTask com onNonConfigurationChangedInstance ().

     // Declaire a member vairiable private UpdateTast task; public void onCreate(){ // Attempt to get the asynctask instance task=(UpdateTask)this.getLastNonConfigurationInstance(); // If it's null create a new instance if(task==null){ task = new Updatetask(this.getApplicationContext()); task.execute(). } // If it is not null, then the reference returned by getLastNonConfigurationInstance(); will be used. } // And lastly oviewride onRetainNonConfigurationInstance method: @Oviewride public Object onRetainNonConfigurationInstance() { return task } } // Declaire a member vairiable private UpdateTast task; public void onCreate(){ // Attempt to get the asynctask instance task=(UpdateTask)this.getLastNonConfigurationInstance(); // If it's null create a new instance if(task==null){ task = new Updatetask(this.getApplicationContext()); task.execute(). } // If it is not null, then the reference returned by getLastNonConfigurationInstance(); will be used. } // And lastly oviewride onRetainNonConfigurationInstance method: @Oviewride public Object onRetainNonConfigurationInstance() { return task } } // Declaire a member vairiable private UpdateTast task; public void onCreate(){ // Attempt to get the asynctask instance task=(UpdateTask)this.getLastNonConfigurationInstance(); // If it's null create a new instance if(task==null){ task = new Updatetask(this.getApplicationContext()); task.execute(). } // If it is not null, then the reference returned by getLastNonConfigurationInstance(); will be used. } // And lastly oviewride onRetainNonConfigurationInstance method: @Oviewride public Object onRetainNonConfigurationInstance() { return task } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.