Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8623881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:23:23+00:00 2026-06-12T07:23:23+00:00

Consider the following scenario: The class TemplateActivity extends Activity . Within onResume() it performs

  • 0

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 method and the activity, and starts a new activity, OtherActivity.

When the class ChildActivity, which extends TemplateActivity, runs, it waits for super.onResume() to finish and then continue no matter if its super needs to start the Intent or not.

The question:
Is there a way to terminate the ChildActivity when the OtherActivity needs to start from the TemplateActivity? Without implementing the validity check in the child class.

Superclass:

class TemplateActivity extends Activity {
    @Override
    protected void onResume() {
        super.onResume();

        if(!initialized)
        {
            startActivity(new Intent(this, OtherActivity.class));
            finish();
            return;
        }

        //Do stuff
    }
}

Subclass:

class ChildActivity extends TemplateActivity {
    @Override
    protected void onResume() {
        super.onResume();

        //Do stuff
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:23:24+00:00Added an answer on June 12, 2026 at 7:23 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following scenario: class A<T> {} class B extends A<Integer> {} How can
consider the following code scenario: <?php //widgetfactory.class.php // define a class class WidgetFactory {
Consider the following two scenarios: //Data Contract public class MyValue { } Scenario 1:
Original Question Consider the following scenario: public abstract class Foo { public string Name
Consider the following scenario (this is not production code): class MyClass { public function
To paint a scenario, consider the following logic-omitted-Service public class Service { private Validator
Please consider the following scenario: Class Class1 Function Func() as String End Function End
Consider the following scenario: My form model public class PersonForm { @NotNull private String
Please consider the following scenario. I have a form with a property: class MyForm
Consider the following scenario: public class Entity1 { virtual public Int32 ID { get;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.