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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:50:30+00:00 2026-06-09T20:50:30+00:00

I’m just a beginner with android and trying to develope an app with all

  • 0

I’m just a beginner with android and trying to develope an app with all kind of basis features to get familiar with them. I’m trying to safe a setting of the textview color, chosen by the user. This color is lost when the orientation changes. I’ve read multiple threads about how to save things for orientation change but all those examples are with strings or boolean etc.
saving activity state

I want to save a value from an xml file. So I have to save a piece of code that sets the color and not a primative datatype.

Part of the code that sets the color:

public void onClick(DialogInterface dialog, int item) {
    switch(item){
        case 0:
            mWelcomeUser.setTextColor(getResources().getColor(R.color.purple_color));
            break;
        case 1:
            mWelcomeUser.setTextColor(getResources().getColor(R.color.red_color));
            break;

Part of the xml file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="purple_color">#A420A0</color>
    <color name="red_color">#FF0000</color>
    <color name="green_color">#00FF00</color>
    <color name="black_color">#000000</color>
    <color name="blue_color">#0000FF</color>
    <color name="grey_color">#828282</color>
</resources>

Now I want to save the colorsetting in onPause() and retrieve it in onResume(). But I cant figure this out. I’ve tried to put it in an int (color) something like this:

public void onPause(){
    super.onPause(); 
    color = mWelcomeUser.getCurrentTextColor();
}

public void onResume(){
    super.onResume();
    mWelcomeUser.setTextColor(color);
}

What is the easiest way to do this?

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-06-09T20:50:32+00:00Added an answer on June 9, 2026 at 8:50 pm

    When orientation changes android pauses the running activity or destroys it.So i set the onPause() as well as onDestroy() methods to hold the text color and in onCreate() and onResume() we will again get the text color.I used SharedPreferences to solve your problem.

    I am providing the answer below….

    private SharedPreferences mPrefs;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);
    
        SharedPreferences mPrefs = getPreferences(MODE_PRIVATE);
        mWelcomeUser.setTextColor(mPrefs.getInt("currentColor", Color.RED));
    }
    
    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
    
         SharedPreferences mPrefs = getPreferences(MODE_PRIVATE);
         mWelcomeUser.setTextColor(mPrefs.getInt("currentColor", Color.RED));
    }
    
        @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    
        SharedPreferences.Editor ed = mPrefs.edit();
        ed.putInt("currentColor", mWelcomeUser.getCurrentTextColor());
    
        ed.commit();
    }
    
    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
    
        SharedPreferences.Editor ed = mPrefs.edit();
        ed.putInt("currentColor",  mWelcomeUser.getCurrentTextColor());
    
        ed.commit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group

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.