Best way to check if picture already seen - android

My Android app grabs random pictures from a Django server. And in my app, you can vote on the picture.
I want to be able to make sure the user never gets the same picture twice. I already am saving an array of integers that has the picture id locally on the app itself.
My question is, what would be the best/good practice to have the server send only new pictures that haven't been voted on?
I was thinking of sending the server the array of integers so that the server can cross check and send back one that wasn't already voted on, but thinking this could be a problem on a larger scale -> making the server do too many computations.
Thanks in advance!

I don't know much about Django, but either you need to do as you suggested, or you can ask for a random picture, the server responds with the ID it intends to send and your app replies with either yes or no depending on whether it wants that one. The server then either offers another random ID or you accept the picture and it sends it.
Also, use a set instead of an array - you have no interest in order, you just want to avoid duplicates.

Related

Should we use backend code or Client side code for e-commerce android app

I am working on an android e-commerce app and recently I'm having little doubts on some concepts.
Should I include my functions in the client side apk or on the online servers (like Google functions, Amazon lambda)?
For example an user adds an item in his cart
Should I include my code in the client side apk like:
Get the item's price and multiply it with the quantity and then add to the total price of cart.
Or should I just send the data from the client side apk like:
Send the unique ID and quantity to the specific function in online functions
And then put the multiplying and stuff... in the online functions.
Where should I include these calculations?
I think the important thing here is how you're managing state. When the user adds something to their cart, does the app tell the server they've done that? Do they have a cart on the server, with a list of what that user has added so far? Or does it all happen on the user's device, and the server doesn't know anything about the cart until they go to check out?
If the cart is managed on the server, I'd say it's better to let that handle all of the state, and let it tell the device what to display. If the user adds 2 items, tell the server what they've added, and the server can say "your cart contains this" and include the price in that information. It gives you more control, because your server is the source of truth - you're not relying on the device to get it right (which sounds silly but a lot of weird things can happen)
Whatever you do though, don't let the user's device tell the server how much the items cost! If it's calculating the total for the user then fine, so long as it's for display purposes. But when it comes to calculating how much the items cost at checkout, you do that yourself, server-side - take item IDs and counts from the user, nothing else. If they fake a request that says 50 gold watches for $1, you'll be in big trouble!
That might be obvious but I had to put it out there just in case!
It depends on where you're calling that function from. If you're calling that function from somewhere in your front end code, you should include it in your client. If you're calling the function from somewhere in one of your Lambda or Google functions, then you should put it there.
The concept that you might want to learn about is called scope. Wherever a function is in scope, some thing else can call it. You might consider looking up the rules for scope in your specific programming language.

Best practice to post data with web-services

I created an android app where I tap on the screen to put some waypoints , get their position and some extra data, then post the data using cakephp. I want to know what are the best practice to send data for my case ?
Example, should I post every point once I tap on the screen or store all the data and post it once for all or post every point into a temporary table then when I click submit I post the data to the real table ?
I really want to know if there are other solution to optimize my application and the loading time ! Thanks.
If the positions are not used by other users until the user completes their interaction I'd save all the positions and send them as a http POST in JSON format as an array [[0,100],[100,331]] or [{"x":0,"y":100},{"x":100,"y":331}] depending on if you're really wanting to optimize it or not use one or the other.
If the positions are used by other users on the site in real time, send every position as they are selected.

Android transfer object data through different device, same app

I want to implement a feature in an app where users can add friends and check and compare each other stats from the java objects created, which involves a few subclasses.
I was wondering if anyone know what the best way to approach this would be?
The only thing that pops out is using Firebase. Where the user would click a button to upload the data to Firebase with a UUID link, and then give the UUID to the other user, where he/she would have to manually type the UUID in a textfield, and it gets the data from Firebase.
Would method be viable and is there any other better options?
Thanks
I would probably create a file (you can invent any ending) with all info you need displayed in json. That file can be shared via Whatsapp or what ever and imported in your app?
But I don't know what "stats" that are that the users can compare but I think they will change from time to time? So I would guess an online service would be better because otherwise to update, they have to share again and again?

Best method to store and read data from a cloud source in Android?

The situation: I have many real life locations with specific information associated with them, and updated frequently. I am unsure of how to store this information for use in an android application.
My original thought was storing the data on some server/cloud source/database, reading from the server from each Activity in the app to make sure the info is up to date, and update the server with any changes that may or may not have been made.
For example: there are 200 people inside the library, one person leaves.
So we would read the number of people from the server, display this on the app, person leaves, subtract one, send the new number back to the server.
Would this be an incorrect approach? I'm fairly new to Android in general, and I really have no experience on how to approach this type of situation, what services to use, etc.
I would look into using Parse, its a pretty sweet way to power the backend, and their website is very detailed in explaining how to use it.

Cache for list of friends / items

I'm looking for a way to cache as much data as possible in my app. Most of this data, are items which are crucial for the following steps, like a list of friends. Depending on the selected friend I show a list with certain items and can send something to this friend.
I would like to cache the list of friends. In such way, that it's not possible to send something to a non-existant friend, which would obviously cause an error. Or maybe the cache could work such that it shows a "invalid cached friend" message and refreshes after it...?
The list of friends will not change very frequently but still can change while the user is using the app.
I also want to cache the items which can be sent to the users. These also will not change very frequently, but it's very important that the user doesn't send non-existent items, and it's of course desirable that they see the newest items, if they were updated on the server side.
It's the same principle like caching items which can be bought, for example. It's critical that the users doon't try to complete a transaction with an invalid item.
I have already done some research, but could only come up with a rough idea so far:
Compare data using hash or timestamp: In this case I don't know at which point to do it? Loading the screen probably doesn't make any sense, since the user would have to wait for the server's response anyways. Maybe a background process? But how often do I run it? How do I synchronize?
Also, I can add an update menu item such that the user can ensure that the data is updated. But it still doesn't solve the problem that the user can try to complete transactions with invalid data (if they don't press the button).
I also found some information about "real time data" and AVIs but I think that's not applicable for my case, my data will change seldomly, but it's required that it's valid, since it's not only informative data, it's transaction determining data.
What is the way to handle this?
I think you are right, you should check the timestamp with the data source (the server).
If that's a peer-to-peer exchange between friends, just before sending your data, request its timestamp from the server. Not so much data, usually close to real time. But there's still some minor probability of sending obsolete data - just "a nanosecond" after an update.
If it's through the server (and why not?), as a bonus, you will have optimistic locking by checking the timestamp on the server and canceling the transaction if the data being sent is obsolete.

Categories

Resources