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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:56:41+00:00 2026-06-07T13:56:41+00:00

I am developing a carpool application using our mCruiseOn platform. I have 2 activity’s

  • 0

I am developing a carpool application using our mCruiseOn platform. I have 2 activity’s that I need to code, both the activity’s have 90% the same code/flow and functionality. I can create a layout xml and just include it in both my layout’s but how do I manage the code part of it. The intent is to not duplicate code, but yet keep it clean and manageable.

I need the common code to manage the findViewById, setOnClickListener and onClick method. As a example, both activities take start and end locations in gps. Both activity’s have a time/date dialog button.

Some thoughts

  1. So GetGPSAndTimeActivity where I do all the findViewById, onClickListener, onCreateDialog. Then should I extend from GetGPSAndTimeActivity ?
  2. Use Fragments like Fragment in Android 2.3.3 and lesser

I prefer option 1.

  • 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-07T13:56:42+00:00Added an answer on June 7, 2026 at 1:56 pm

    That depends on your situation. Lets say you have an Activity A that does some stuff and an Activity B that does exactly the same stuff like A but a little bit more (like adding a few buttons).

    In that case you can let Activity B extend your Activity A.
    B just adds what’s missing.

    If Activity A and B have a lot in common, but if there are also slight differences, to be precise: if Activity A contains code that is not needed by B you should create one abstract base class C for both activities A and B which contains only the common sub-set of code. Let A and B extend C and add to A and B their individual extra-code.

    As for using Fragments or not: I’d go for it. In the long run you’ll have less troubles with supporting tablets / multiple screen sizes and you can easily re-use them in different contexts.

    Let’s assume your boss / client suddenly wants that fancy ViewPager feature we know from Google Play (swiping screens left and right for switching categories). If you were using Fragments in the first place, this change can be done very easily and quickly.
    If you were using Activities instead, you need to re-arrange a great deal of code.

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

Sidebar

Related Questions

iam developing one application.In that i need to get the music files from the
Developing for iPhone, I have a collection of points that I need to make
Developing iphone application using makkit framework. I have got the map view integrated in
Developing a network application, I have a Connection class that manages sending and receiving
Developing an MVC application, i now need to have test other browser versions. Installed
Developing an application using SWT to work in both Linux and Windows. I created
Developing a project of mine I realize I have a need for some level
Developing a C# .NET 2.0 WinForm Application. Need the application to close and restart
Iam developing one application.In that iam placing the radio buttons(uiimageview) on table view and
While developing an application using gwt in ecliplse crashed. Now the server is running

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.