Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not write spaghetti-code/huge activities w/Android?

Tags:

android

I'm trying to avoid having gigantic activity classes that are hard to follow, but the platform seems to be making it hard. Doing almost anything requires a activity or context - these can be stored away in a helper class, but unfortunately calls like startActivityForResult, for example, don't take a sperate listener but always call back on the same activity on an override with a supplied integer code - so this means that seperation of concerns is hard - the main activity needs to know about the helper class and dispactch to the helper class based on an request code - and of course, that request code needs to be unique, so that's a leaky abstraction as well. Why not specify a listener for every call thus avoiding the dispatching and need for unique request codes? Any other ways to slice this? thanks

like image 480
thelazydogsback Avatar asked Jun 28 '11 19:06

thelazydogsback


People also ask

Why is a spaghetti code not recommended when writing a program?

Spaghetti code is when the code you work with is unstructured by nature, tightly coupled, and contains an unnecessary amount of mental translation between reality and its representations. The issue with spaghetti code is that the lines composed for the software are not easy to mentally digest.

Is my code spaghetti code?

Spaghetti code occurs when certain conditions are met: A programmer or programmers did not take care to finesse the architecture using programming constructs, and instead relied on easier, or less thought out approaches, or just dove into a project and started coding without a plan.

What is spaghetti code in C++?

Code that overuses GOTO statements rather than structured programming constructs, resulting in convoluted and unmaintainable programs, is often called spaghetti code. Such code has a complex and tangled control structure, resulting in a program flow that is conceptually like a bowl of spaghetti, twisted and tangled.


1 Answers

In API level 11 and higher, you can use Fragments.

like image 73
Steve Prentice Avatar answered Oct 21 '22 04:10

Steve Prentice