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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:26:33+00:00 2026-06-12T12:26:33+00:00

I’m having an issue with preserving the data entered by a user on my

  • 0

I’m having an issue with preserving the data entered by a user on my android activity classes. I have identified I need to make use of the onSavedInstanceState(Bundle outState) method but the way my program is written makes this difficult.

A user enters a variety of data in DataEntry.java class and the information they submit is displayed on DataSummary.java. This works fine.

But when a user navigates away from DataSummary.java say, to fill in the rest of the information on DataEntry.java the original submitted data is lost if you go back to DS.java to see what you’ve written already. Below is the code for DataSummary.java.

public class DataSummary extends Activity {

ImageView resultImage;
TextView resultName; 
TextView resultDescription;
TextView resultType;
TextView resultProject;

public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState); 
   setContentView(R.layout.activity_data_summary);

   //Check if there is anything in the 'bundle' and if not produce message - AVOIDS NULLPOINTEREXCEPTION when navigating to Activity
   Bundle bundle = this.getIntent().getExtras();     
   if (bundle != null){
   int image = bundle.getInt("image");
   String name = bundle.getString("key");
   String description = bundle.getString("key1"); //gets data from DataEntry activity
   String type = bundle.getString("key2");
   String project = bundle.getString("key3");

   resultImage=(ImageView)findViewById(R.id.resultImage);
   resultName=(TextView)findViewById(R.id.resultName);  //adds the TextViews to the activity
   resultType=(TextView)findViewById(R.id.resultType);
   resultDescription=(TextView)findViewById(R.id.resultDesc);
   resultProject=(TextView)findViewById(R.id.resultProject);

   resultImage.setImageResource(image);
   resultName.setText(name); // Fills the textviews with imported data
   resultType.setText(type);
   resultDescription.setText(description);
   resultProject.setText(project);
   }    

   else
   {
       Toast.makeText(DataSummary.this,"Received no data yet!", Toast.LENGTH_LONG).show();
   }

}

/* MANAGES ACTIVITY LIFESTYLE */
public void onSavedInstanceState(Bundle outState){  
    super.onSaveInstanceState(outState);
}

How can I expand on the onSavedInstanceState method to get the imported data which is received when the Activity is created and preserved it if a user navigates away from this activity? Hope that’s well explained enough?

It is difficult to figure out how to make use of the variables in onCreate as well as I cannot access them from another method (I think if I knew how to do this I could complete the method).

  • 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-12T12:26:36+00:00Added an answer on June 12, 2026 at 12:26 pm

    You can set static variables on your class. When the user enters the data, you just write that data on your variables. When the user comes back to the app, you just write the data stored in your variables into your EditTexts.

    EDIT: Example

    Let’s assume you have 2 EditTexts et1 and et2, and the values they store are username and mail.

    public class DataEntryActivity extends Activity{
    
        private static String username;
        private static String mail;
    
        @Override
        public void onCreate(Bundle b){
             super.onCreate(b);
             setContentView(R.layout.layout_data_entry);
             EditText et1 = (EditText) findViewById(R.id.editTextUsername);
             EditText et2 = (EditText) findViewById(R.id.editTextMail);
             if (username != null)
                  et1.setText(username);
             if (mail != null)
                  et2.setText(mail);
             Button save = (Button) findViewById(R.id.saveButton);
             save.setOnClickListener(new OnClickListener(){
    
                  public void onClick(View v){
    
                       if (et1.getText().toString().length() > 0)
                            username = et1.getText().toString();
                       if (et2.getText().toString().length() > 0)
                            mail = et2.getText().toString();
                       Intent intent = new Intent(DataEntryActivity.this, YourOtherActivity.class);
                       startActivity(intent);
                  }
    
             });
    
        }
    
    
        public static String getUsername(){
             return username;
        }
    
        public static String getMail(){
             return mail;
        }
    
    }
    

    From your other activity you just have to call DataEntryActivity.getUsername() and DataEntryActivity.getMail() to get them back.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.