简体   繁体   English

如何在Android屏幕之间预先填充数据

[英]How to pre populate data between the screens in android

I have an app with 3 screens. 我有3个屏幕的应用程序。

For each screens i have next button in each screen to go to the next screen. 对于每个屏幕,我在每个屏幕中都有一个下一个按钮以转到下一个屏幕。

problem: 问题:

Scenario 1: 方案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? 我该如何在android中进行管理?

Thanks in advance... 提前致谢...

You can save the data in Shared preferences. 您可以将数据保存在“共享”首选项中。 Check this : Shared Preferences Android and Example 检查一下: Android的共享首选项示例

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 阅读此内容: 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. 进入onCreate方法后,您可以重用该数据,也可以使用活动标志来确保后向堆栈中只有一个活动实例。

            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);
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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