Android - Cannot apply decorator pattern to actions?

I would like to be able to dynamically create an Activity with multiple the capabilities that we have (for example, prevent scrolling, monitor Internet connection, prevent orientation changes, etc.).

We do not want to create an abstract BaseActivityone that contains all possible properties and abstract methods for all possibilities. We would have many empty function implementations in subclasses BaseActivitythat would need to actually implement several of these functions. Even worse, if we think about another possibility (another set of properties and functions to add to BaseActivity), we will need to edit EVERY child BaseActivityto implement new abstract functions (most likely, it will be empty).

Another approach to inheritance BaseActivityis to create child classes that implement only some of the features that we have. But this will require us to create a child class for each combination of features, which is too much even with few features. In addition, this will lead to a large number of duplicate codes for 2+ child classes that will implement the same features.

So, I thought about implementing the Decorator pattern, but I don't think we ever created a new activity. We always create Intentand specify SomeActivity.classin our constructor, then callstartActivity(new Intent(getApplicationContext(), SomeActivity.class));

Is there a way to intercept the actual creation of an Activity instance, execute Pattern Decorator processing on it, and then let OS / Application put it on top of the stack?

, ?

0
2

BaseActivity, .

, abstract. .

Activity, Pattern Decorator, OS/Application ?

Android.

, ?

- BaseActivity, " ". . , , , , .

Activity. onCreate(), onStart(), onResume(), onPause(), onStop(), onDestroy(), onSaveInstanceState(), onRestoreInstanceState() . , ( onCreate()). , , (, onSaveInstanceState() ) .

+1

, .

0

All Articles