简体   繁体   English

Android Studio中的标签/活动问题

[英]Issues with tabs/activities in android studio

We're making an app for counting drinks in android studio, thats the main function. 我们正在开发一个用于在android studio中计算饮品数量的应用,这就是主要功能。 We also have an activity to add drinks/prices from stores, and on the main activity, if we have counted to a number and switch back and forth between the activities, the number goes away. 我们也有一个活动来添加商店中的饮料/价格,在主要活动中,如果我们计算了一个数字并在活动之间来回切换,该数字就会消失。

Basically, the question is, is there any way to make the main activity to stay active while switching back and forth? 基本上,问题是,有没有办法使主要活动在来回切换时保持活动状态?

When you go from one Activity to another, you should store the data that you want transferred to another Activity as an extra in the Intent. 从一个活动转到另一个活动时,应将要转移到另一个活动的数据作为额外的存储在Intent中。 At the start of the new Activity, you retrieve the extra data again. 在新的活动开始时,您将再次检索额外的数据。 Try the Android developer docs here 此处尝试Android开发人员文档

Another option is to use a Singleton pattern where you store all your temporary data. 另一种选择是使用单例模式来存储所有临时数据。 As long as your app is active, regardless of the Activity your temporary data will be available. 只要您的应用处于活动状态,无论处于“活动”状态,您的临时数据都将可用。 There's plenty of info in Singleton patterns online, here's one. 在线有大量有关Singleton模式的信息, 这是一个。 A little Google search will get you far. 一点点Google搜索就能带您走远。

The easiest way to achieve what you wan't would be to use Android share preferences They are simplest way to share info throw all your app, check the Official documentation . 实现您所不想要的最简单的方法是使用Android share preferences它们是共享信息的最简单方法,可将所有应用程序扔掉,请查看官方文档

Also, check this answer witch describes every method for sharing info throw your android application. 另外,请检查此答案,女巫描述了共享信息的每种方法都将引发您的android应用。

Hope this helps. 希望这可以帮助。

Regards Jose 问候何塞

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

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