简体   繁体   中英

Issues with tabs/activities in android studio

We're making an app for counting drinks in android studio, thats the main function. 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. At the start of the new Activity, you retrieve the extra data again. Try the Android developer docs here

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. A little Google search will get you far.

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 .

Also, check this answer witch describes every method for sharing info throw your android application.

Hope this helps.

Regards Jose

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