I am new to android development. I have developed one app, now the problem is that whenever I rotate screen, app starts activity again and then its crashes application. I found some solution on google to use android:configChanges="orientation" . It works fine but when I rotate screen, its screen size does not change. How to solve this problem ?
Logact :
05-28 14:32:52.038: E/AndroidRuntime(276): FATAL EXCEPTION: main 05-28 14:32:52.038: E/AndroidRuntime(276): java.lang.IllegalArgumentException: View not attached to window manager 05-28 14:32:52.038: E/AndroidRuntime(276): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.view.Window$LocalWindowManager.removeView(Window.java:432) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.app.Dialog.dismissDialog(Dialog.java:278) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.app.Dialog.access$000(Dialog.java:71) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.app.Dialog$1.run(Dialog.java:111) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.app.Dialog.dismiss(Dialog.java:268) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.app.Dialog.cancel(Dialog.java:951) 05-28 14:32:52.038: E/AndroidRuntime(276): at com.MobileWeb.mytestbuddy.PremiumMain$TheTask.onPostExecute(PremiumMain.java:373) 05-28 14:32:52.038: E/AndroidRuntime(276): at com.MobileWeb.mytestbuddy.PremiumMain$TheTask.onPostExecute(PremiumMain.java:1) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.os.AsyncTask.finish(AsyncTask.java:417) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.os.AsyncTask.access$300(AsyncTask.java:127) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.os.Handler.dispatchMessage(Handler.java:99) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.os.Looper.loop(Looper.java:123) 05-28 14:32:52.038: E/AndroidRuntime(276): at android.app.ActivityThread.main(ActivityThread.java:4627) 05-28 14:32:52.038: E/AndroidRuntime(276): at java.lang.reflect.Method.invokeNative(Native Method) 05-28 14:32:52.038: E/AndroidRuntime(276): at java.lang.reflect.Method.invoke(Method.java:521) 05-28 14:32:52.038: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 05-28 14:32:52.038: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 05-28 14:32:52.038: E/AndroidRuntime(276): at dalvik.system.NativeStart.main(Native Method)
You can avoid activity recreation by adding following to your application's manifest file.
android:configChanges="orientation|keyboardHidden|screenSize"
As follows
<activity
android:name=".your activity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name" >
</activity>