Saving a state

Put your problem here if it does not fit any of the other categories.

Saving a state

Postby nithin.warier » Thu Mar 13, 2008 11:02 am

Hi

my program contains two pages. In the first page contains some editbox and a next button. In the second page contain back button.So when i click back button, the values i entered in the first page are not there. But i want to display the values i entered, means saving a state.

any suggestions for my problem..

Thanks
Nithin
nithin.warier
Experienced Developer
Experienced Developer
 
Posts: 87
Joined: Thu Feb 28, 2008 12:05 pm
Location: Malappuram Kerala India

Top

Postby sxjthefirst » Thu Mar 13, 2008 12:01 pm

If I understood the question right...

Did you override the onPause and onResume methods of the first page?

onPause should have the code to save the state depending on how you want to save it.
onResume will have the code to retrieve the saved state.

See Android Tutorial - Exercise 3

Or do you mean something to do with persistent objects which I read can also be done.
sxjthefirst
Developer
Developer
 
Posts: 36
Joined: Wed Mar 12, 2008 7:24 pm

Postby nithin.warier » Thu Mar 13, 2008 12:45 pm

hi sxjthefirst, my code is

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.   public void onCreate(Bundle icicle) {
  2.  
  3.         super.onCreate(icicle);
  4.  
  5.  ageEditText = (EditText) findViewById(R.id.Age);
  6.  
  7.         heightEditText = (EditText) findViewById(R.id.Height);
  8.  
  9.  if(icicle != null)
  10.  
  11.         {
  12.  
  13.             String age = icicle.getString("Age");
  14.  
  15.             String height = icicle.getString("Height");
  16.  
  17.             ageEditText.setText(age);
  18.  
  19.             heightEditText.setText(height);    
  20.  
  21.         }
  22.  
  23.     }
  24.  
  25.  
  26.  
  27.     public void onFreeze(Bundle outState) {
  28.  
  29.             super.onFreeze(outState);
  30.  
  31.            outState.putString("Age", ageEditText.getText().toString());
  32.  
  33.            outState.putString("Height", heightEditText.getText().toString());      
  34.  
  35.     }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


its like this... but its not working... i didnt use onPause().... how to modify this code and make it work..

thanks
Nithin
nithin.warier
Experienced Developer
Experienced Developer
 
Posts: 87
Joined: Thu Feb 28, 2008 12:05 pm
Location: Malappuram Kerala India

Postby sxjthefirst » Thu Mar 13, 2008 1:04 pm

Looks OK to me too... did you try adding breakpoints and debugging to see when the onFreeze method is called aqnd if it is called at all at the point you want?

Sorry for such a basic question :)
sxjthefirst
Developer
Developer
 
Posts: 36
Joined: Wed Mar 12, 2008 7:24 pm

Postby nithin.warier » Fri Mar 28, 2008 6:58 am

Hi sxjthefirst,

Thanks for your comment, i slightly modified the code and now its working, put all the declaration at the end...

Thanks
Nithin
nithin.warier
Experienced Developer
Experienced Developer
 
Posts: 87
Joined: Thu Feb 28, 2008 12:05 pm
Location: Malappuram Kerala India

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests