Prevent the exchange of orientation from updating the Activity

Asked

Viewed 413 times

3

I have a problem, an Activity of mine has a list of multi-selectable objects, with the long click I can select several of these objects and click the remove button, when I click to remove, appears a dialog Progress that runs by an Assynctask.

The problem is that when I change the orientation of the smartphone (either changes to Portrait or Landscape) the view is updated, and this causes the thread to stop causing an error, how do I prevent this error? Or prevent assynctask from stopping without fixing an orientation?

Error:

java.lang.IllegalArgumentException
WindowManagerGlobal.java line 372 in WindowManagerGlobal.findViewLocked()
android.view    
WindowManagerGlobal.java line 372 in WindowManagerGlobal.findViewLocked()
android.view    
WindowManagerGlobal.java line 301 in WindowManagerGlobal.removeView()
android.view    
WindowManagerImpl.java line 84 in WindowManagerImpl.removeViewImmediate()
android.app 
Dialog.java line 332 in Dialog.dismissDialog()
android.app 
Dialog.java line 123 in Dialog$1.run()
android.os  
Handler.java line 808 in Handler.handleCallback()
android.os  
Handler.java line 103 in Handler.dispatchMessage()
android.os  
Looper.java line 193 in Looper.loop()
android.app 
ActivityThread.java line 5292 in ActivityThread.main()
  • vc has tried to use this statement in manifest.xml: android:configChanges="orientation|screenSize|Keyboard|keyboardHidden"

  • worked out, but according to Google, you should not do this, and my layout gets weird, especially the admob banner that is not changed since the view does not update, then it is small

  • Have you tried using a AsyncTaskLoader? As they you will not have problems with changing orientation, since their life cycle is managed by ActivityManager.

  • cannot use async Loader, because besides using Progress dialog with Dismiss at the end, when this Dismiss runs, changes occur in the UI, well at least I do not know how to make changes inside the asynctaskloader... I don’t think so

  • maybe some way to block the rotation while the assync runs? this is possible?

  • Leave it, I blocked the screen even, I could not find a solution on google... But it would be good if someone responded by giving the example of this configChanges, or something else for me to accept here

  • Yes, it is possible to block the rotation of the screen while the AsyncTask is executed. I don’t know if it’s that bad, since she goes back to normal after... But using the AsyncTaskLoader you would use the method onLoadFinished to update the interface, and then no matter if the orientation has changed, it will run in the next Activity (Assuming you started the update in which it was destroyed).

Show 2 more comments

1 answer

2

To resolve this issue open the file AndroidManifest.xml, then in your Activity statement add the following line:

android:configChanges="orientation|screenSize"

Example:

<activity
    android:name="com.example.activity.MainActivity"
    android:configChanges="orientation|screenSize"
    android:label="@string/app_name" >
</activity>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.