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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:57:12+00:00 2026-06-14T17:57:12+00:00

I read almost all article about onSaveInstanceState and onRestoreInstanceState in Stack overflow but I

  • 0

I read almost all article about onSaveInstanceState and onRestoreInstanceState in Stack overflow but I cant solve my problem.
I have a text view and button in my main.java and while you click on button value of a ( a is an int variable) variable will increase and show in the text view, but, when I rotate my phone ( orientation change), text view reset.

I override onSaveInstanceState and onRestoreInstanceState but it doesn’t work.
one more thing, I have special layout-land.xml file for landscape view.

here is my code

 import android.app.Activity; 
 import android.graphics.Typeface; 
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;
 import android.widget.TextView;

 public class main extends Activity {
     /** Called when the activity is first created. */   
   public int a = 0;     
   public String fonts="TAHOMA.TTF";

   TextView tv = (TextView) findViewById(R.id.salavat);      
   Button b = (Button) findViewById(R.id.showsalavat);

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       b.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View arg0) {
               a++;
               tv.setText(""+a);
            }
       });
   }
   @Override        
   protected void onSaveInstanceState(Bundle SavedInstanceState) {
      super.onSaveInstanceState(SavedInstanceState);            
      SavedInstanceState.putInt("salavat-count", a);
   }
   @Override    
   protected void onRestoreInstanceState(Bundle savedInstanceState) {
       super.onRestoreInstanceState(savedInstanceState);     
       a= savedInstanceState.getInt ("salavat-count");   
   } 
}

and here my main.xml

    <TextView
        android:id="@+id/shoma"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:text="@string/shoma"
        android:textSize="20sp" />

    <Button
        android:id="@+id/showsalavat"
        android:layout_width="fill_parent"
        android:layout_height="150dp"
        android:text="+"
        android:textSize="100sp" />

    <TextView
        android:id="@+id/eltemas"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="55dp"
        android:text="@string/eltemas" />

    <TextView
        android:id="@+id/salavat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="35sp" />

    <TextView
        android:id="@+id/ferestade"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="24dp"
        android:text="@string/salavat"
        android:textSize="20sp" />

</LinearLayout>

I really need some help on this.
I really appreciate your help.

  • 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-14T17:57:13+00:00Added an answer on June 14, 2026 at 5:57 pm

    I think this code is helpful for you..

    public class MainActivity extends Activity 
    {
    
        protected void onSaveInstanceState(Bundle outState) 
        {
            super.onSaveInstanceState(outState);
            System.out.println("TAG, onSavedInstanceState");
    
            final TextView text = (TextView)findViewById(R.id.textView1);
            CharSequence userText = text.getText();
            outState.putCharSequence("savedText", userText);
        }
        protected void onRestoreInstanceState(Bundle savedState) 
        {       
            System.out.println("TAG, onRestoreInstanceState");
            final TextView text = (TextView)findViewById(R.id.textView1);
            CharSequence userText = savedState.getCharSequence("savedText");
            text.setText(userText);
        }
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            final String name = "5";
    
            final TextView show = (TextView)findViewById(R.id.textView1);
            Button btn = (Button)findViewById(R.id.button1);
            btn.setOnClickListener(new View.OnClickListener() 
            {
    
                public void onClick(View v) 
                {
                    // TODO Auto-generated method stub
    
                    show.setText(name);
    
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read almost all articles about Repository pattern and different implementations of it.
In almost all books and articles I have read about about HIGHMEM in Linux
I've read almost all the other questions about the topic, but my code still
I read an article about a regular expression to detect base64 but when I
I have a problem, I tried to look at almost all the poster solutions,
Almost all of the Delphi code I have read has all the class type
Almost every article I read told me that you can't have chdir in Java.
Well, I DID READ ALMOST ALL THE QUESTIONS HERE ABOUT THIS TOPIC! I need
Almost all of the examples in the jQuery tutorials that I've read, usually use
Almost anywhere I read about programming with CUDA there is a mention of the

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.