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 8557535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:35:43+00:00 2026-06-11T15:35:43+00:00

I have two activities almost doing the same thing. The only thing that differs

  • 0

I have two activities almost doing the same thing. The only thing that differs them is a URL to be parsed.

What is considered best practice regarding Android development, subclass just to set the URL or send the URL via an intent?

public SuperActivity extends Activity{
    protected String pageUrl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        [...lots of stuff...]
        super.onCreate(savedInstanceState);
    }
}

public SubActivityOne extends SuperActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        pageUrl = "http://urlOne.com"
        super.onCreate(savedInstanceState);
    }
}

public SubActivityTwo extends SuperActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        pageUrl = "http://urlTwo.com"
        super.onCreate(savedInstanceState);
    }
}

or

public SuperActivity extends Activity{
    private String pageUrl;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Bundle extras = getIntent().getExtras(); 
        pageUrl = extras.getString("intent_key_url");
        [...lots of stuff...]
        super.onCreate(savedInstanceState);
    }
}
  • 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-11T15:35:45+00:00Added an answer on June 11, 2026 at 3:35 pm

    In your case, I would subclass, but do it slightly differently than you. It’s dangerous to put some code in onCreate when it’s not definitely needed. (You may get lost in your hierarchy and not call exactly what you want to call in the correct order) I would use an overriden method rather than a variable. Do that:

    public abstract SuperActivity extends Activity{
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            [...lots of stuff...]
            // instead of using pageUrl, use a method when you need it: pageUrl()
            super.onCreate(savedInstanceState);
        }
    
        protected abstract String pageUrl();
    }
    

    And your subactivities would look like: (only one shown here)

    public SubActivityOne extends SuperActivity{
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }
    
        @Override
        protected String pageUrl() {
            return "http://urlOne.com";
        }
    }
    

    The intent way is good too, but it might become complicated if later on you want to add more differences in your subactivities. With subclasses, it’s very flexible.

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

Sidebar

Related Questions

I have two activities in my app. One is a list that is presented
Let assume we have two activities. A - main activity, that is home launcher
I want to know that if I have two activities in a program then
I have two Activities in my Android app that deal with NFC. One has
I have two activities A and B. B : is a setting activity that
I have two activities with exactly same intent filters and I would like to
I have an Android application that contains two Activities . Activity A has a
I have two activities, A and B. Activity A implements a LocationListener that periodically
I have two Activities that both list items in a table. For the time
I have two activities that both contain an identical context menu built programmatically using

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.