Implementing a Shopping Cart [closed]
Asked Answered
C

3

6

I am making an Android app where I am implementing a Shopping Cart. When the user selects an item, it is added to his/her shopping cart/bag in the app. Once he/she adds an item, he's presented with the menu again, where he can add more items. Now I want to know how do I save these items during the buying process. I mean the items that are being saved in the bag, how do I save them in my android app? Shall I use the Android SQLite database? or use putextra/getextra and navigate through activities? or shall I use Global Variables (something like subclassing the Application class)?

Or is there any other better way to implement such a thing? The details that I need to show in my bag are: the name of the product, its price, quantity and a few other attributes/options related to the product.

Conciliatory answered 30/6, 2012 at 6:28 Comment(2)
use SQLite DB and define DBhelper, which will be more flexible for all DB CRUD operations.Taoism
@kb_14, how did you implemented this feature? Please share your info.Horrify
L
4

Passing the shopping cart items around in extras or using an Application class is too volatile. If your app crashes, the user exits the app, android decides to close your app, .. basically anything that closes your app.. The user will lose the contents of their shopping cart.

SQLite would be a good option for storing data like this. You could also store the shopping cart in an xml file on the user's phone.

Lott answered 30/6, 2012 at 6:36 Comment(2)
How does this saving an xml file on the user's phone work? What is the difference between saving an xml file on the user's phone and SQLite database?Conciliatory
@Conciliatory This was ages ago now, but I think developers have access (or could have access upon request) to the user's local SD card.Faultfinding
T
2

Is there any other better way to implement such a thing?

First of all you have to understand that what is Shopping Cart Software? However you may develop shopping cart client (Tutorials) in android.

The shopping cart system has server-application (which you may develop using the RESTful web-services,servlets and filter) and client-application (you may develop a web-client or Android client). The RESTful web-services, which expose Shopping Cart API and you may interact them (Web-services) with Android UI and network API (Apache http client).

Tiffany answered 30/6, 2012 at 6:36 Comment(5)
could you give me links where I can find more details about RESTful web-services with the Shopping Cart APIConciliatory
I guess I'll have to pay for such a Shopping Cart service which is not possible for me at the moment. That's why I was thinking of saving the data myself in the code or through the SQLite database.Conciliatory
@Conciliatory It is all about you. You may develop both JavaEE webapp/web-service and android client. Did you visit that link (tutorial)?Tiffany
Yes. and that's what I will probably try to follow. Let me see and implement the thing and then I'll come back to you if I have any problemConciliatory
@AVD please check out my question here (#29163880)Handout
F
2

One way is to have your shopping cart stored in a public static variables. Since I had to implement the shopping cart for few of my Android apps, I have tried to create a library project for it.

You can check it out here: https://github.com/tonyvu2014/android-shoppingcart and an example on how to use the library is here: https://github.com/tonyvu2014/android-shoppingcart-demo

Forgetmenot answered 23/4, 2015 at 10:26 Comment(1)
Missing a screnshot of the end result. It is important because it gives idea whether it is someone have in mind or not. Having APK or installable at Playstore is a +1Larynx

© 2022 - 2024 — McMap. All rights reserved.