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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:28:32+00:00 2026-06-16T23:28:32+00:00

I am considering using the android Application class as a place to store temporary

  • 0

I am considering using the android Application class as a place to store temporary state and common code shared by other (fragment) activities in the app.

I would like to get more feedback as to whether it is a good place for:

  1. Shared constants like ID’s, pref key names, etc.
  2. Global variables (i.e. setters/getters) reflecting current UI state, navigation, selected fragment, and, in general, temporary data that does not need to be persisted.
  3. Hooks for persisting data when certain conditions are triggered.
  4. Updating the UI after preference changes.
  5. Providing an easy way to access the context from anywhere in the app, including code where getApplication() is not available, e.g. via a static getter such as MyApp.getApp().
  6. Common methods that need the visibility of the global state variables and which would become too cumbersome to move away to dedicated classes.

What else would be appropriate/useful/handy to have in the activity class? What would not be a good idea to keep in it and what would be the best alternatives? And finally, what you have found Application to be best used for in your apps?

  • 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-16T23:28:33+00:00Added an answer on June 16, 2026 at 11:28 pm

    Shared constants like ID’s, pref key names, etc.

    I generally create a constants file called C for this, as its better for readability. C.SHARED_PREFS is easier to understand that Application.SHARED_PREFS IMHO.

    Global variables (i.e. setters/getters) reflecting current UI state,
    navigation, selected fragment, and, in general, temporary data that
    does not need to be persisted.

    This would be better off in the Activity or component which it concerns (for example, the UI state of an Activity should probably stored in the icicle bundle, or within that instance of the Activity).

    Hooks for persisting data when certain conditions are triggered.

    This should be fine.

    Updating the UI after preference changes.

    Again, I feel this would be better off in the respective component.

    Providing an easy way to access the context from anywhere in the app,
    including code where getApplication() is not available, e.g. via a
    static getter such as MyApp.getApp().

    This would work, but be careful of memory leaks. You should generally pass the context in as a parameter when calling the method from an Activity or Service or whatever. Less chances of a memory leak.

    Common methods that need the visibility of the global state variables
    and which would become too cumbersome to move away to dedicated
    classes.

    I feel it would be better to make the effort of dedicated classes, as when your app grows in features and size, this will become difficult to maintain.

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

Sidebar

Related Questions

I'm considering using Adobe Air to write an application for the android marketplace. I
I'm considering using a persistent connection to a cloud service from an Android app.
We are considering using Cassette in our asp.net web application which might be accessed
I'm considering using memcached (at some point) in my application i'm currently developing. Eventually,
I am considering using ClickOnce for a legacy Windows Forms application. I have several
I'm using the built in sqlite library on the Android platform. I'm considering adding
I am considering using an NSMutableDictionary in place of my current NSMutableArray. This is
I have been considering using the code example shown at Shell Style Drag and
I'm considering building an application for Windows Phone 7, Android, iphone, ipad, and potentially
Is there any way to draw optimal route(considering traffic) between two geopoints using Android

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.