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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:06:35+00:00 2026-05-22T21:06:35+00:00

I wanted to know what is the best approach for sharing singleton in my

  • 0

I wanted to know what is the best approach for sharing singleton in my android app.
I have a few activities that does not rely on each other, but I want them to have a singleton that they can all read/write.

Where should I place it?

Thanks

  • 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-22T21:06:36+00:00Added an answer on May 22, 2026 at 9:06 pm

    Your application should be a singleton. It avoids many other problem related to sharing datas or models.

    In your manifest.xml :

    <application android:icon="@drawable/icon"
        android:label="@string/app_name" android:debuggable="false"
        android:name="<class of your application see below>" 
                android:launchMode="singleTop">
     ..... all activities/services/receivers/etc... as usual
    
    </application>
    

    And your android:name refers to this class :

    public class MyApp extends Application {
    //singleton, but use onCreate more than constructor to build shared resources.
    ....
    }//class
    

    And then, from within any activity, you can retrieve your singleton to get shared resources by doing this :

    ((MyApp)getApplicationContext()).getSharedResources()....
    

    or

    MyApp.getInstance().getSharedResources()....
    

    Having a singleton as a app is a usual design pattern in android, it is especially useful to handle device rotation (as it tends to destroy activities and recreate them) as it provides a stable entity to persist during app lifecycle.

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

Sidebar

Related Questions

Just wanted to know what is the best approach (in terms of speed and
Since silverlight does not have any support for DataSets/DataTables, what would be the best
I wanted to know what's the best approach to take on, when starting work
i wanted to know what's the best approach to develop such an epg matrix
I wanted to know the best way to check if the numbers are not
I wanted to know which would be best suitable - EDM or reflection provider
I wanted to know, the best methodology (with code sample please) of having a
I wanted to know that if I am doing correctly, regarding retain and release
I know that similar questions have been asked all over the place, but I'm
I wanted to know what the community considers the best practices in respect to

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.