CompositeAndroid Course


Welcome to CompositeAndroid Online Course with live Instructor using an interactive cloud desktop environment DaDesktop. Experience remote live training using an interactive, remote desktop led by a human being!


7 hours

₱46,873


What is CompositeAndroid?


Composition over inheritance Allows to add functionality into an Android Activity. Just because we all have a BaseActivity in our projects containing too much unused stuff. When it grows, it get unmaintainable.

Possible Usecases

State of the Art

Given you have an Activity showing a list of tweets (TweetStreamActivity) and you want add view tracking.

Inheritance

You could do it with inheritance and use TrackedTweetStreamActivity from now on: public class TrackedTweetStreamActivity extends TweetStreamActivity { @Override protected void onResume() { super.onResume(); Analytics.trackView("stream"); } } more likely you would create a TrackedActivity and extend the TweetStreamActivity from it: public abstract class TrackedActivity extends AppCompatActivity { public abstract String getTrackingName(); @Override protected void onResume() { super.onResume(); Analytics.trackView(getTrackingName()); } } public class TrackedTweetStreamActivity extends TrackedActivity { @Override public String getTrackingName() { return "stream"; } } Both solutions work but don't scale well. You'll most likely end up with big inheritance structures: class MvpActivity extends AppCompatActivity { ... } class BaseActivity extends AppCompatActivity { ... } class BaseMvpActivity extends MvpActivity { ... } class WizardUiActivity extends BaseActivity { ... } class TrackedWizardUiActivity extends WizardUiActivity { ... } class TrackedBaseActivity extends BaseActivity { ... } class TrackedMvpBaseActivity extends BaseMvpActivity { ... }

Delegation

Some libraries out there provide both, a specialized Activity extending AppCompatActivity and a delegate with a documentation when to call which function of the delegate in your Activity. public class TrackingDelegate { /**

  • usage:
  • {@code
  •  
  • @Override
  • protected void onResume() {
  • super.onResume();
  • mTrackingDelegate.onResume();
  • }
  • } */ public void onResume() { Analytics.trackView(""); } } public class TweetStreamActivity extends AppCompatActivity { private final TrackingDelegate mTrackingDelegate = new TrackingDelegate(); @Override protected void onResume() { super.onResume(); mTrackingDelegate.onResume(); } } This is an elegant solution but breaks when updating such a library and the delegate call position has changed. Or when the delegate added new callbacks which don't get automatically implemented by increasing the version number in the build.gradle.

    Composite Android solution

    CompositeAndroid let's you add delegates to your Activity without adding calls to the correct location. Such delegates are called Plugins. A Plugin is able to inject code at every position in the Activity lifecycle. It is able to override every method.



Course Category:

   Mobile Development Training

Last Updated:

  


Course Schedules


Date Time
June 8, 2023 (Thursday) 09:30 AM - 04:30 PM
June 22, 2023 (Thursday) 09:30 AM - 04:30 PM
July 6, 2023 (Thursday) 09:30 AM - 04:30 PM
July 20, 2023 (Thursday) 09:30 AM - 04:30 PM
August 3, 2023 (Thursday) 09:30 AM - 04:30 PM
August 17, 2023 (Thursday) 09:30 AM - 04:30 PM
August 31, 2023 (Thursday) 09:30 AM - 04:30 PM


CompositeAndroid consultancy is available.

Let us know how we can help you.


CONSULT US