简体   繁体   中英

How to pre populate data between the screens in android

I have an app with 3 screens.

For each screens i have next button in each screen to go to the next screen.

problem:

Scenario 1:

--> I filled the data in first screen

--> I go to the second screen.

--> When i come back to the first page i am able to see the data what i filled.

-->But when i again go to the second page i am not able to see the data what i filled in the second form.

How can i manage this in android?

Thanks in advance...

You can save the data in Shared preferences. Check this : Shared Preferences Android and Example

Hope this helps.

You need to save the state yourself using your activities' lifecycle methods. Read this: http://developer.android.com/training/basics/activity-lifecycle/recreating.html

You can save temporary data in application data. Once in the onCreate method, you can reuse that data, or you can use an activity flag to ensure that there's only one instance of your activity in the backstack.

            try
            {
                //in first run app. go to catch and in other go to try
                SharedPreferences pref = getSharedPreferences("pref",0);
                SharedPreferences.Editor edit = pref.edit();
                String x= pref.getString("login", null);
                edit.commit();
                if(x.equals("first"))
                {
                    //here you can fill editbox by value you entered before
                    edt1.setText(x);
                    //and make this way to all edittext 
                }
            }
            catch(Exception e)
            {
                SharedPreferences pref = getSharedPreferences("pref",0);
                SharedPreferences.Editor edit = pref.edit();
                edit.putString("login",edt1.getText().toString());  
                //edt1.getText().toString() value(s) you want to save
                edit.commit();
                Intent intent = new Intent(getApplicationContext(), First.class);
                startActivity(intent);
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM