Skip to content Skip to sidebar Skip to footer

Finish Subclass Activity From Its Superclass

Consider the following scenario: The class TemplateActivity extends Activity. Within onResume() it performs a validation of a boolean variable then, if false, it finishes the meth

Solution 1:

A more elegant solution would be a slightly different approach to the class design:

  1. Introduce a method DoStuff() (replace with sensible name) in the TemplateActivity . Do all the // do stuff bits there.
  2. Call this method from the end of TemplateActivity OnResume
  3. Override it in the child activity to extend it with the child activity // do stuff bits.
  4. Do not override onResume in the ChildActivity.

This way, if the condition fires in TemplateActivity OnResume, none of the parent and child DoStuff will be done. The ChildActivityshouldn't have to know anything about this behavior.

Solution 2:

I guess this is what you're trying to get:

classChildActivityextendsTemplateActivity {
    @OverrideprotectedvoidonResume() {
        super.onResume();
        if (!isFinishing()) {
            // Do stuff
        }
    }
}

Post a Comment for "Finish Subclass Activity From Its Superclass"