Rotation of screen crashes android app [duplicate]

坚强是说给别人听的谎言 提交于 2019-12-10 10:28:06

问题


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)


回答1:


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>



回答2:


Your question is so vague. All I can say is you need to check your log cat and have a read and see why your application crashes.

I would recommend a quick read on android:configChanges from here. Hope this helps you.



来源:https://stackoverflow.com/questions/16787918/rotation-of-screen-crashes-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!