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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:50:47+00:00 2026-06-12T09:50:47+00:00

The thing is: when I started to learn developing for android, I thought I

  • 0

The thing is: when I started to learn developing for android, I thought I would store my internal datas in public static variables within a dedicated class, for this purpose only, so I could access them from any activity easily, and it was and still is pretty important, that there won’t be any duplicate, and theese values are always unique, something like a Singleton model. This is working awesomely, tho it is not the prettiest solution for sure. The problem starts when the user puts the application to the background via home button. It remains there for god knows how much time, maybe minutes, maybe days, or even more…then he reopens the application, and all theese static variables became null, since the system already destroyed them. Some of theese variables are simple Strings, but some are pretty complex, own classes.

The first question is, is there any global hook that I can rely on, where I can save theese datas, when the app goes to the background? So when the user pulls the app to the foreground again, I could just reinitialize theese variables from the saved state.

The second question is, what would be the best way to save theese complex datas? As far as I understand, for saving Strings SharedPreferences are just fine, but what about the more complex classes? Can I use SharedPreferences as well, or should I use something else?

For now this is all I can think of, thx for the help in advance!

  • 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-12T09:50:48+00:00Added an answer on June 12, 2026 at 9:50 am

    Bad idea with the whole static variables in class. Ignoring the whole global variable debacle, they don’t persist. You should use SharedPreferences or a database if you need to persist data.

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

Sidebar

Related Questions

I recently started using Masterpages, the thing is I would like to add text
I'm new to programming and thought Python would be a good language to learn.
Hi for the last month I have started to learn CSS.Fist thing I did
I just started to learn objective-c and one thing is not clear for me
I have just started to learn the Play 2.0 Framework. The one thing I
I just started with backbone.js, and one thing that I noticed is that sometimes
I started a demonstration project on HTML, JSON and jQuery recently. Thing I want
I've just started learning MATLAB, and the first thing i tried is to plot
I just recently started to experiment with .NET MVC 4. The thing is I
I started to learn cpp and encountered cin as a way to receive input

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.