简体   繁体   English

将数据从一个活动传递到另一个活动

[英]passing data fromone activity to another activity

I am new at developing Android.I have a activity A that has a listview.When I clicked the item on listview,activity B is launched to view detail of selected item of listview.Then when I clicked the option menu item(Edit) on activity B ,activity C is launched to edit detail of selected item of listview.After editing the detail,I want to trasfer detail of item from activity C to activity A.Data of listview is hold arraylist on activity A. My question is how can I obtain (by which method) detail of item coming from activity C to activity A. Please help me to get rid of the problem. 我刚开始开发Android。我有一个具有列表视图的活动A.单击列表视图上的项目时,将启动活动B以查看列表视图中所选项目的详细信息。然后单击选项菜单项(编辑)活动B,活动C启动,以编辑列表视图中选定项目的详细信息。编辑详细信息后,我要将项目的详细信息从活动C转移到活动A。列表视图的数据保存在活动A上的数组列表。 我的问题是我(通过哪种方法)获得了从活动C到活动A的项目详细信息。请帮助我解决该问题。 A(list)--->B(show)--->C(edit)--->A(list) A(列表)---> B(显示)---> C(编辑)---> A(列表)

Do not transfer complex data from one activity to another, instead use like in web pages do. 不要将复杂的数据从一个活动转移到另一个活动,而要像在网页中那样使用。 Passing something like querystrings and then retrieve the data based on the key submitted from one activity to another. 传递类似查询字符串的内容,然后根据从一个活动提交到另一个活动的键检索数据。

See code below: This is the First Activity calling the second activity and passing two variables. 请参见下面的代码:这是第一个活动,它调用第二个活动并传递两个变量。

var focus = new Intent(this, typeof(Focus));
                    Bundle newextra = new Bundle();
                    newextra.PutString("ID", ID.ToString());
                    newextra.PutString("Step", step.ToString());
                    focus.PutExtras(newextra);
                    StartActivity(focus);

Then at the next activity you can retrieve data as follow: 然后,在下一个活动中,您可以按以下方式检索数据:

Bundle extras = Intent.Extras;
        var id = int.Parse(extras.GetString("ID"));
        var step = int.Parse(extras.GetString("Step"));

Then retrieve the data from local storage (database or something) 然后从本地存储(数据库等)检索数据

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

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