Search code examples
androidrotationrssrss-reader

How to prevent error when rotating device while RSS feed loads


I have developed a small app that reads and rss xml file from my own link. The application runs fine.

However, I have noticed that when I rotate the phone before the feed loads completely the application crashes.

Also if I rotate the device after the RSS feed loads, the Activity reloads the feed again. Anyone know what or why the crash happens?

I was thinking of the following 2 solutions:

  • Force the Activity to be in portrait layout all the time.

  • Disable the rotation while the RSS feed loads and then release after. If that is at all possible.

Any suggestions?

Sorry for a delay... the following is the trace i got:

09-15 09:53:31.209 30468-30468/com.rrrrrrrr.xxxxxxxxxx E/ViewRootImpl: sendUserActionEvent() mView == null 09-15 09:53:31.754 30468-30468/com.rrrrrrrr.xxxxxxxxxx E/ViewRootImpl: sendUserActionEvent() mView == null 09-15 09:53:31.769 30468-30468/com.rrrrrrrr.xxxxxxxxxx E/AndroidRuntime: FATAL EXCEPTION: main 09-15 09:53:31.769 30468-30468/com.rrrrrrrr.xxxxxxxxxx E/AndroidRuntime: Process: com.relentlessdev.maleadvise, PID: 30468 09-15 09:53:31.769 30468-30468/com.rrrrrrrr.xxxxxxxxxx E/AndroidRuntime: java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{78a8658 V.E..... R.....ID 0,0-1696,464} not attached to window manager


Solution

  • The best I can think (As you have not provided any code snippet) of is that you are missing very important point related to android activity. Activity in android is created again from scratch whenever screen rotation changes. Most probably there is some NullPointerException in your code when activity is created again. There are couple of methods to handle screen rotation in android at activity level. The best solution according to me would be to override

    public void onConfigurationChanged(Configuration newConfig)
    

    for Activity class and handle the rotation yourself.