Dilemna : prevent StackOverflowException or improve user experience?

In my application, I have 2 list activities which can start one or the other by clicking on their items.

|--Activity1--|           |--Activity2--|           |--Activity1--|
|   item11    | ->click-> |   item21    |           |   item21    | ->click-> ...
|   item12    |           |   item22    | ->click-> |   item12    | 
|   item13    |           |   item23    |           |   item13    |
|-------------|           |-------------|           |-------------|

So if the user clicks too much, he can fill all the stack and the system will throw a StackOverFlowException won't it ?

The solution I chose then was to tag these 2 activities with noHistory="true", but now I regret that the user can't navigate between these 2 activities with the back button.

Can someone help me to find a better alternative ?

Thanks in advance

EDIT: to be more comprehensive, let's explain what is this activity workflow goal :

I have a database which store a list of names linked to a list of days in a year. A name can be linked to multiple days, and same thing a day can be linked to multiple names.

the database schema 

|  names  |---< n, m >---|  days  |

So this activity workflow is a kind of database navigator :

  • Activity1 is the NameListActivity, it displays a list of names linked to a specific day.
  • Activity2 is the DateListActivity, it displays a list of days linked to a specific name.

When user clicks on an item (a name) of the NameListActivity, the DateListActivity is started with the list of days linked to the clicked name.
And same thing, when user click on an item (a day) of the DateListActivity, the NameListActivity is started with the list af names linked to the clicked day.

Asked by: Alissa370 | Posted: 24-01-2022

Answer 1

So if the user clicks too much, he can fill all the stack and the system will throw a StackOverFlowException isn't it ?

No, it won't.

Answered by: Audrey652 | Posted: 25-02-2022

Answer 2

I don't see why removing the ability to go the Activity1 from Activity2 would deteriorate the user experience. I believe that you mentally create a hierarical list in your head when you navigate this type of menus, so when clicking on item22 I would get confused if I was sent back to Activity1.

I need more details about the content of the menus to suggets another design, but you might be best of rethinking the menu system.

Answered by: Melissa864 | Posted: 25-02-2022

Answer 3

As I understand it, Android's "stack" of activities isn't a "stack" in the traditional sense, and memory is managed in a more intelligent way. The activities stack actually goes on the heap, and the OS will kill the activities lower on the stack if it needs to.

I would say the worst that will happen is you lose some old history.

If you want to test it, allocate a large amount of memory in each activity so that 5 or 6 will fill the available memory, then try it.

Answered by: Owen503 | Posted: 25-02-2022

Answer 4

commonsware is correct. You won't have to worry about a stack overflow. :) However, you can design the app to clear the stack to avoid the situation you described. Look into Clearing the Stack, specifically the use of clear top.

Answered by: Elise186 | Posted: 25-02-2022

Answer 5

What you need to do is to store the history in some structure, rather than relying on the stack to maintain it for you. Then you can maintain your good user experience and not blow the stack.

Answered by: Agata899 | Posted: 25-02-2022

Answer 6

Try to remove this noHistory="true" and instead put android:launchMode="singleTask" http://developer.android.com/guide/topics/manifest/activity-element.html#lmode But Mark @commonsware you'll be fine as it is.

Answered by: David217 | Posted: 25-02-2022

Answer 7

I'm having similar problems with my application. Seems that the problem lies in number of nested views for each activity. So, if you have, for instance:

    linear layout->
        linear layout->
                  linear layout->

and maybe several more nestings, the odds that you'd get stack overflow after getting from such view to a similar one and back several times (in my experience) are high. Check the nesting with hierarchyviewer (android-sdk/tools). Also tell me if you fix the problem, because I still don't know how to fix it...

Answered by: Kelvin335 | Posted: 25-02-2022

Similar questions

java - StackOverflowException when serializing binary tree

I'm attempting to implement a binary tree for an Android app, and I want to be able to serialize it to a file on the device. Unfortunately, I'm getting stackoverflow errors when trying to serialize it. Code: class BTree&lt;V extends Model&gt; implements Serializable { /** * */ private static final long serialVersionUID = 4944483811730762415L; private V value; private BTree&lt;V&gt; left; privat...

android - StackoverflowException Occurring while coping a folder

When the following code executes with more number of nested folders and files the it gives StackOverflowException Please suggest me the way to avoid it. public void copyDirectory(File sourceLocation , File targetLocation){ try { if (sourceLocation.isDirectory()) { if (!targetLocation.exists() &amp;&amp; !targetLocation.mkdirs()) { throw new IOException("Cannot create...

Getting Stackoverflowexception in query.getInBackground - parse.com android SDK

I always get stackoverflowexception when I try to query a parse.com object based on ObjectID. Has anyone else this problem or is there any workaround to avoid this exception? (I tried different versions of SDKs, different parse.com accounts - but the exception still exists) Any help would be appreciated :) Steps to reproduce: 1) Download sample android starter project 2) Import as exis...

android - why am i getting a StackOverflowException when testing a GridViewPager with Robolectric

i'm trying to add a test for the activity in the android wear implementation and getting a stack overflow exception. the test: @Test public void testActivityInit() { Robolectric.buildActivity(CustomGridActivity.class).create().start().visible().get(); } the exception: java.lang.StackOverflowError at sun.misc.Unsafe.compareAndSwapInt(Native Method) at java.u...

android - Clearing image in CircularImageView does not work | StackoverFlowException while setting image in CircularImageView

I am using https://github.com/Pkmmte/CircularImageView to get the picutures circular. And I want to clear the image in imageView if it is set already. NONE of the solutions work suggested @ How to clear an ImageView in Android?. Any help on how ca...

java - Sync data to server in chunks leads to StackoverflowException

I am syncing huge data in chunk using onSuccessCallBack() interface method.Sending data to server in following approach shown in image. Here I am facing issue of StackOverflowException. How can I avoid it. Should I implement BroadcastListener and will broadcast from NotifySyncCompleted() method after every cycle completion.Here in OnReceive() method of BroadcastListener I can call NextChunkSync() method.

android - Why parsing StackOverflowException throws OOM?

I noticed, app users got error: Fatal Exception: java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack available So, I had written pretty simple app: public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); s...

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android