creating method or wait()/notify() in android game - android

So I will describe what I am trying to doing general.
I have customers(the number of customers available varies at times due to weather, events, or location)
I have a drink stand ( depending on certain factors serving times vary and added time to refill pitcher)
The amount of customers coming to stand vary based on price, events, and popularity.
Customers come to stand and if another customer is still at stand getting served then the others wait in line behind each other. (after so much time in line they complain about wait times)
I want there to be a day timer so even if stand isnt finished serving customers then he loses them because wait time.
So I am not sure if using the Wait()/Notify() way would be best. I was thinking that maybe if I setup Customers as a class and brought it into the activity I am running the sales day in with the Stand info. I would appreciated help with finding a way to do this. I am still going through some other tutorials to see if I can understand a way to do this without screwing up.

Found out that I need to send the customers into a queue when I have them arrive at the stand.
Then also, the day timer will need to be set up to work off a countdown timer.

Related

Feasibility of perfectly syncing number counter between app and server?

First time asking a question. I appreciate any thoughts/feedback you may have.
Part of the functionality of an app I am working on requires that an internal counter in the app be in perfect sync with a counter on a remote server.
More specifically, there are 86,400 seconds in a day. Assume on a server I start a counter that ticks from 1 to 86,400 progressing at one tick a second. When it gets to 86,400 it starts over at 1. This then repeats indefinitely.
Part of the functionality of the app is the first time it is launched by the user it will connect to the server and sync a similar running counter within the app to perfectly match the counter on the server. (e.g. at the exact same time that the server counter ticks to perhaps 10,215.....so should the app counter be ticking to 10,215.)
Assume perhaps thousands of users have the app. I need it so that the thousands of individual app users now have 1 - 86,400 counters all running exactly in sync with each other. With the idea that a user only has to have their app perform this server sync a single time. After it's synced, the counters within the apps would then run in unison in perpetuity.
Questions:
1) Is this feasible to do? For the reasons I need this to occur, it literally cannot be off by even a second or two. They all have to match perfectly.
2) Would varying internet and/or phone speed by user be a problem (during the sync process)? Again, it is a one time sync. It does not have to sync on a continuous, real-time basis. Nonetheless, the first sync does have to be perfect.
3) If the answer to the above is that it is doable.....getting greedy here, can I sync it at even faster speeds? Instead of the counter just counting up one tick per second (i.e. 86,400 ticks per day), can the counter tick at perhaps a rate of 1/10 of a second (864,000 ticks per day). At that super fast tick speed, could the perfect sync still be accomplished?
While not the exact reason for needing the above, to give perspective.....imagine I had 100 people sitting in a room download the app. They then open the app which then all perfectly sync to the server so that they are all now running their individual counters in perfect unison. At that point, they lose internet connectivity (yet, the counter continues to run within the app in their phone.) If the app was programmed to start playing a particular song when the internal app counter reached tick X, all 100 phones would start playing the song at the exact same time (when their counters in unison reached tick X).
Sorry for the long question, but wanted to lay out my issue. Thanks everyone!

Android time logger with millisecond precision and error estimation

Short skippable intro:
I work at a rehabilitation hospital that's a couple kilometers from where I live. The hospital pays a bus service that picks the employees up at certain fixed locations. There's this bus driver, that picks us at 7:00. The guy is FREAKISHLY PUNCTUAL. I mean, this guy has to be in the tenth of a second order. The clock turns from 6:59 to 7:00 EXACTLY when he opens the bus door. And I was thinking of recording his punctuality for like 30 days and make a nice Excel spreadsheet for him. Error propagation and everything. He might even get a raise, who knows?
I'll make a simple app to save time in milliseconds, that seems easy enough, there're like half a dozen solutions for that here in Stackoverflow.
So, to the question:
I hit a button on a widget. It gets a time in ms. It saves it on a file (.txt, .csv, whatever)
How would you estimate the mean error of an NTP synchronized Android phone? What's the most precise and exact way to save a timestamp?
Thanks in advance
First thing that comes to mind is that time is relative, in the Einstein kind of way :) So if your reference is an Android phone synchronized with NTP, what is the driver's time reference? What if synchronization or timing somehow gets off, delayed on your phone and you have the impression that he's late one day, when in fact he's precisely on time relative to his reference?
But for the sake of solving the problem i think you can start by assuming he has the same time reference with you: some place in a network. I don't know the details of Android synchronization via time protocols, but i do know i built a so called Network Synchronization API. In your case i think my Java API might be of help. It tries to make a request for the number of milliseconds since the Unix epoch and then reads the response. The feature is that it gives you a framework on which you can estimate your true time compared to the server's by trying to discard network lag.
One thing to bear in mind: the solution above makes a request to my site (a.k.a. GoDaddy servers) which is probably different than the network location Android phones sync with. Feel free to change the request location.
Second thing to bear in mind: this rabbit hole goes deep :) No measurement can be perfect. You can try to achieve human / reasonable precision but it can never be perfect (e.g. there are other unknowns: what if there's a lag in your Android CPU just as you press the button, or what if your own reaction takes a few milliseconds? The moment you press the button is not the same as the moment the doors actually open and my impression is they're at least a few millis apart)

android: do something in certain time

I was read almost all article that have same question in Stackoverflow and somewhere else but those made me confuse.
my problem: I want my App toast something in certain time to the user (like alarm clock App that start ring in certain time) as an example, I want my App 2 days and 10 hour latter show a toast. but, during this period every thing maybe happen like application close, phone will restart or Etc... and the App doesn't show any thing.
my question is: How can do something in certain time in android App?
So now what is the solution? can any one help me and give me a sample code plz?
thank you in advanced,
What you want is an AlarmManager
You can also find a tutorial here. If you are scheduling a precise time, you might want to actually be conservative and wake yourself up a little early, then schedule a toast using a Timer for finer grained control.

Battery notification in every application that is running

Is it possible to have a battery notification in every application that is running?
For example: If I'm going to run an application like Angry Birds, is it possible to have some sort of a notification that will tell me if there is enough time to continue playing it?
This is one of the objectives in our thesis.
If I'm going to run an application like Angry Birds, is it possible to have some sort of a notification that will tell me if there is enough time to continue playing it?
You can play Angry Birds for a second, a minute, an hour, a day, a week, a month, etc. There is no defined "enough time to continue playing it".
Moreover, it is impossible to state definitively how much power a process will run in the future.
Now, you could create some code that attempts to measure historical power consumption of an application (and how the user uses it, which may vary from person to person). You could use that information to make some educated guesses about how long the user could keep using that app. And you could find a way to present that information to the user.
All of that will require, at minimum, custom firmware. It is also very possible that it will require custom hardware that has fine-grained power consumption data collection, such as the Qualcomm MDP.

Time since the app is open in android

Hello
In my android application i would like to get Time since when the app is opened.
Initially what i tried was getting the time when the app is loaded from the server and then taking the difference with the current time from the device.But by doing that if the user changes the time then i willnot be getting the actual time.
Its not posiible to hit the server again for the same.
Is there any way to achieve this in android?
Please share your valuable suggestions.
Thanks in advance:)
Try the "SystemClock" class, "uptimeMillis()" method.
Store the result in a variable when the app starts.
Echoing what I said for your other question, you first need to become familiar with the activity lifecycle and understand the novel meanings (almost meaninglessness) of common words like "open" and "start" in the life of an android app.
There isn't any way you can prevent the user from changing the system time - you just don't have the right to do that to users. Normally this should be a rare event, unless you do something that makes them want to, such as lock them out of a free version of your app after so many minutes. (However if the phone is on a mobile network, presumably the mobile network occasionally adjusts its time to correct for errors in the device's oscillator, or administrative time changes)
What you can do is check the system time on every entry point to your application. If it ever goes backwards, well... something is going on. If the clock has been set back, you could assume no time between the calls with the negative time difference and resume your time meter from there, at least keeping all the previous used time in your record.
It may be that there are cpu cycle counters which you could query and correlate to system time, but this may be highly device specific and may in fact be resettable. And it may get weird if the cpu frequency is demand throttled.
You might be able to set a countdown timer as a bound on the maximum possible time between entry points at which you could meter. I don't know if these work reliably across system time changes or not - ideally they would. Testing or reading the source will reveal.
Use elapsedRealtime in your onCreate() store it. More reliable.

Categories

Resources