Implementing a Shopping Cart

31,044

Solution 1

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.

Solution 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).

Solution 3

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

Share:
31,044
kb_14
Author by

kb_14

Android, iOS, Full Stack Dev, Python, Python-Flask, Python-Django, ReactJS, Blockchain, Bitcoin, Ethereum, Stellar and other Crypto

Updated on February 23, 2020

Comments

  • kb_14
    kb_14 over 3 years

    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.