How not to write spaghetti code / huge actions with Android?

I try to avoid giant classes of activity that are difficult to complete, but the platform seems to complicate it. Performing almost anything requires activity or context - they can be stored in a helper class, but, unfortunately, calls like startActivityForResult, for example, do not accept a sperm listener, but always return to the same action when overridden with the provided integer code - so this means that separation of problems is difficult - the main activity is to know about the helper class and send it to the helper class based on the request code - and, of course, this request code must be unique, so that the leak abstractions. Why not specify a listener for each call, thereby avoiding scheduling and the need for unique request codes? Any other ways to cut this? thanks

+7
source share
2 answers

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

+2
source

The task of the listener will be difficult, because for this it will be necessary to transfer the object to other processes in the Android environment - remember that actions can be called from one application to another.

How is the request code used, making your actions "huge" so that listeners do not? Activities should use classes defined elsewhere to do most of the work, so that your actions relate primarily to user interface tasks.

0
source

All Articles