سؤال

--> I've implemented threading in my first activity. And made the use of progress dialog also. So now during the orientation (of that screen only) my application crashes - gives exception of memory Leaked. And as a solution of this I came to know from here only that I should put

android:configChanges="keyboardHidden|orientation"

But now my onCreate() method of that activity is not getting called, and it is necessary for me to call this method on orientationChanges. So what should I do at this stage?

هل كانت مفيدة؟

المحلول

Check out this blog:

http://blog.doityourselfandroid.com/2010/11/14/handling-progress-dialogs-and-screen-orientation-changes/

There are also other similar questions here on stackoverflow: How to handle screen orientation change when progress dialog and background thread active?

I have experienced, if using the first option, that the emulator has a bug which makes it call onCreate() twice - causing a crash, but it shouldn't be an issue on a real device.

نصائح أخرى

Add this to your manifest file

  android:screenOrientation="landscape" or android:screenOrientation="portrait"

example :

 <activity android:name=".SomeActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait">

Do you really want to handle the orietation changes for you app?

If not, you can set the screenOrientation attribute in the manifest.xml file, so your app will keep in that orientation, no matter how your phone's orientation is.

If you do, you should override this method public void onConfigurationChanged (Configuration newConfig), here you can handle the configure(orientation, keyboard hidden, etc) changes for you app. If you don't override this, the system will simply shutdown you app and restart it. This would result in memory leakage.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top