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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:56:37+00:00 2026-05-23T08:56:37+00:00

Is it possible to get device aspect ratio before launching any activity? I am

  • 0

Is it possible to get device aspect ratio before launching any activity?

I am trying to setup the width based on whether my device is identified as ‘long’ or ‘not_long’. This should be available long before the activity is launched but I am not sure where I can get this variable. Activity is NOT available at the time this method is executed. Also in order to avoid memory leaks I do not want to pass activity into the class that contains the following method.

Here is the failing call method:

public int getDefaultWidth() { 
        Configuration myConfig = new Configuration();
        myConfig.setToDefaults();
        myConfig = getResources().getConfiguration();

        switch (myConfig.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK) {

            case Configuration.SCREENLAYOUT_LONG_NO: {
                return this._defaultWidth;
            }
            case Configuration.SCREENLAYOUT_LONG_YES: {
                return this._defaultWidthLong;
            }
            case Configuration.SCREENLAYOUT_LONG_UNDEFINED: {
                return this._defaultWidth;
            }
        }
        return this._defaultWidth;
    }
  • 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-23T08:56:37+00:00Added an answer on May 23, 2026 at 8:56 am

    Your app’s Application context is created before any activities. An Application has a valid context, so you could use that to fetch whatever you need, set a static or member variable, and then reference that in your first activity.

    An Application context can be handled by adding a new class that extends Application and making a small change in AndroidManifest.xml

    Manifest:

    <application android:enabled="true"...
       android:name=".Foo">
    ...
    </application>
    

    Add the new class to your project that extends Application:

    public class Foo extends Application {
    
    private int mWidth;
    
    @Override
    public void onCreate() {
        super.onCreate();
        // do stuff to set mWidth using the Application context like:
        // mWidth = getResources().getConfiguration().blahblahblah
    }   
    
    public int getWidth() {
        return mWidth;
    }
    

    From your activity, simply do this to get width:

    int width = ((Foo)getApplication()).getWidth();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to get the IP address of the device using some code?
I have a WinCE device. Is it possible to connect to the device from
Assume Applications Foo an Eggs are on the same Android device. It's possible for
I'm writing RESTful service with C#/wcf and need to put filters on GET. Like
Possible Duplicate: getContentLength() returning -1 on some devices and not others I'm doing on
I am writing my own API to perform some of the functionality of the
I'm doing some user tests of my new iOS app and store some test
I have an app where I would like to select a user in my
I've got a driver for a custom PCI card, which builds and runs fine
To prepare to submit my app to the appstore i changed the provisioning profile

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.