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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:55:41+00:00 2026-06-17T21:55:41+00:00

I have defined a global variable inside an activity, this variable changes depending on

  • 0

I have defined a global variable inside an activity, this variable changes depending on the button user has pressed.

If I go outside of my app UI and come back by holding the home button which shows the list of recent apps, then my variable keeps its state, but if I run my app again by pressing the app aicon the variable state is gone.

Is there a way to keep the state of the variable?

  • 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-17T21:55:42+00:00Added an answer on June 17, 2026 at 9:55 pm

    You can save the variable’s value during the onSaveInstanceState() callback. Then you use the “icicle” parameter that is passed to and onCreate() to restore the value. You might be interested in reading Managing the Activity Lifecycle.

    Also note that Java has class variables and member variables but not global variables.

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

Sidebar

Related Questions

Let's say we have an array defined as a global variable. int array[] =
I have defined a global object in a .js file. For example file1.js contains
I have defined a table type PL/SQL variable and added some data there. create
I have defined a rectangle drawable like this: <shape xmlns:android=http://schemas.android.com/apk/res/android android:shape=rectangle> <corners android:radius=4dip/> <solid
This should be a very simple rails question. I have a variable like the
I have a global JSON variable where I store some parameters and then each
I need to edit a variable (array) that is defined outside of the function,
I have a server, which uses a global variable to store the next available
I want to declare a global variable inside an MFC application, so that every
I have question about global variable in Objective-C. I have two .m files :

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.