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

  • SEARCH
  • Home
  • 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 9236323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:15:52+00:00 2026-06-18T07:15:52+00:00

I have many activities in which I need to execute some code on create,

  • 0

I have many activities in which I need to execute some code on create, this code has to do with display preferences such as different themes, hiding the status bar etc.

This is an example of one of the activites:

public class MainActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    }
}

Base activity in turn has this code:

public class BaseActivity extends Activity{

        // getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // System.out.println("BaseActivity");

}

I’m trying to run some code on create but I cannot manage to do it. How can I run the code from above as soon as possible using BaseActivity?

  • 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-18T07:15:53+00:00Added an answer on June 18, 2026 at 7:15 am

    call super.onCreate(Bundle bundle) in the childs onCreate method to call the onCreate of the parent.

    This is a common practice to abstract code from an Activity for reuse in other activities.

    e.g.:

    public class MainActivity extends BaseActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           Log.v(TAG,"MainActivity");
        }
    }
    
    
    
    public class BaseActivity extends Activity{
    
        protected static final String TAG = "TAG";
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             Log.v(TAG,"BaseActivity");
        }
    }
    

    I personnaly do this a lot but I often prefer the following for having better maintainable code:

    composition over inheritance

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

Sidebar

Related Questions

I have an application that depends on connection It has many Activities.I need to
I have a TripDecorator which decorates a Trip object. A Trip has many Activities.
I have many activities. Each one of them has an intent which refers to
In my application I have many classes and activities. Droid is a class which
I have a Location activity that can be called from many activities, such as
I have many Activity which need to override onKeyDown event as below: @Override public
I have an app that goes between many different activities. One activity, my main
I have an application with many activities, sharing the same Menu, which is created
I have an app working that is GPS based. It has many activities and
I have an NSString which has escape characters etc in it. I need to

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.