tags:

views:

49

answers:

2

I have a login page which has a Advanced button. The button sets a view where a user can add some information. When I click save, it goes back to my main view (loginpage) and all info is cleared?

How can I save the state of the first view when navigating away and then back to it?

Thanks

+2  A: 

Take a look at the activity lifecycle, described in the activity docs. When an activity goes into the background, as when you start a new activity, it can be deleted and will be recreated when the user goes back to the activity.

Additionally, your view will be recreated when you go through a configuration change, like a change in orientation.

In your case, you probably want to save the state in the onPause() method, and reset it in the onResume() method. One easy way to share state between activities, is via SharedPreferences. See Saving Persistent State for an example.

Mayra
+1  A: 

There are two ways by this u can accomplish your task.

1> By overriding Onpause() and OnResume methods of activity lifecycle. 2> By using Shared preferences also u can do this.

Now it depends on what u want to preserve ie. data in listview or arraylist etc. if u are using listview and arraylist u can accomplish by following code

u can create class..

public class ResultsAdapter extends ArrayAdapter implements Filterable{

private ArrayList subItems; private ArrayList allItems;// = new ArrayList(); private LayoutInflater inflater; private PTypeFilter filter; private OnCheckedChangeListener test;

public ResultsAdapter(Context context, int textViewResourceId, ArrayList items,OnCheckedChangeListener a) {

super(context, textViewResourceId, items);
    //this.subItems = items;
    for( int i = 0;i < items.size();i++){
        subItems.add(items.get(i));
    }
    this.allItems = this.subItems;
    inflater= LayoutInflater.from(context);

    test =a;

}

Now on Oncreate add this

ListView lvr = (ListView)findViewById(R.id.search_results);


    this.m_adapter = new ResultsAdapter(home.this, R.layout.listrow,  
                                          sResultsArr,home.this);
    this.specsAdapter = new FeaturesExpandableAdapter(home.this,new ArrayList<String> 
                                            (),new ArrayList<ArrayList<Feature>>()); 
     lvr.setAdapter(this.m_adapter);

Is this answer you question

Thanks Rakesh

Rakesh Gondaliya
Thanks Raskesh..I am pretty new, so not sure it helpsI have a login page user(EditText), Password(EditText) and an Advanced (Button)The Advanced button will open a view (setContentView) which takes one paramter (URL - EditText filed)I fill out the URL and click the Save (button) and want to go back to the Login screen which should remain filled in...Does that clarify it more?
Martin