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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:26:41+00:00 2026-05-25T15:26:41+00:00

Is there a way to have two different Java code for one Android app?

  • 0

Is there a way to have two different Java code for one Android app? One targeting phone devices and the other targeting tablet devices.

For example, something like HomeActivity.java and HomeActivity-large.java

Basically I would like to make an Android app that has different layout following its resolution.

I know I can use layout-large to have a specific layout for large devices. I’m not sure how to have a specific logic for tablets and another one for phone targets.

The reason I want to do that is that I would like to make an API call on a screen that I don’t want to do on phone.

As an alternative way, I’ve thought in using a boolean (I’m not sure which one) to test what kind of device the app is running on. But I’m afraid it could get messy.

Another thing could be to make a library with all the functionalities of my app and then two different apps using the library. The problem with that solution is that some code is gonna get replicated.

Any suggestion?

  • 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-05-25T15:26:42+00:00Added an answer on May 25, 2026 at 3:26 pm

    Option 1:
    To have one project that compiles to one or more applications you need to use Conditional Compile. Basically, something like this

    //#ifdef Phone
    // do something here
    //#else Tablet
    // do something else
    //#endif
    

    See Java (Eclipse) – Conditional compilation
    for how to Conditional Compile for Android in Eclipse.

    Option 2:
    You could test for screen size at runtime to determine what UI to show. See:

    http://developer.android.com/guide/practices/screens_support.html

    xlarge screens are at least 960dp x 720dp
    large screens are at least 640dp x 480dp
    normal screens are at least 470dp x 320dp
    small screens are at least 426dp x 320dp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to have this: [one[two]][three] And extract this with a regex?
Is there a way in C# to merge two dictionaries? I have two dictionaries
If I have two tables... Category and Pet. Is there a way in LINQ
I have two keyboards connected to my PC, is there any way to know
Is there any way to list all the files that have changed between two
I have this unordered list <ul> <li>two</li> <li>three</li> </ul> Is there a way I
Is there a way to have TortoiseSVN (or any other tool) auto-add any new
I have a Java application which runs on an embedded device. Because different devices
Is there any way to have something that looks just like a file on
Is there a way to have a 64 bit enum in C++? Whilst refactoring

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.