Siva K
Siva K

Reputation: 4968

Stackoverflow error in android app

in my app i am just running between two activities namely A and B. As per the user he switches from A to B then B to A and again A to B then B to A and goes on.

Both these activities are having list views. Every time when the user gets in and gets out i am adding some data that gets stored in the database. Those data are retrieved from an rss feed, some times they use to be very high in number. Because of this rarely i am getting the stack over flow error.

At first i designed my layouts by Relative layout and i have placed my list views inside a relative layout. I got an answer here, that this error may be due to relative layout and so i changed all my layouts to be as linear layout but still the error is happening.

how to overcome this problem

Upvotes: 0

Views: 738

Answers (1)

bluefalcon
bluefalcon

Reputation: 4245

When launching a new activity it is pushed on top of the current task's stack. As shown in the below figure,

                                                                 |->  B - StackOverflow
    | |                 | |               |A|                   |A|
    | |                 |B|               |B|                   |B|
    |A|                 |A|               |A|                   |A|
    ```                 ```               ```                   ```
Before launching   After launching    After launching       Trying to launch
 activity B         activity B         activity A            activity B

So eventually you will run out of space on your Task Stack which causes the stackoverflow error.

Consider using some of the intent flags to clear the Stack history. From your data you have given I think flag should be helpful - FLAG_ACTIVITY_NO_HISTORY. But you need to confirm if that is the behaviour you want, just go through the rest of the activity flags and choose the correct one that suits your application.

Upvotes: 3

Related Questions