Firebase Jobdispatcher - to use or not to use - java

I am developing an App, a simple, but hopefully addictive little game. The user has to solve predefined levels, as quick as possible.
Information on the levels is stored online in an MySQL database, which also contains the average time it took all players to complete a given level. Also, the level-data is stored, locally, in a SQlite database on the phone.
What I want to do is the following. I want to synchronize the average time (from server to phone) and upload the time it took a player to complete a leve (from phone to server).
Ideally this happens each time the player starts the app or finishes a level. For this, I am considering a Firebase Jobdispatcher, but I was wondering if this is overkill or not. For your information: it is not the end of the world if the average time stored on the phone is not entirely up to date. The game will work just fine without it being up to date. On the other hand, I want it to get updated regularly as the performance of the user will be compared to the average time.
I am a beginner, who wants to do things correctly. Hope you can help.

It sounds like you already know when some work should happen. As you said:
Ideally this happens each time the player starts the app or finishes a level.
You don't need JobDispatcher to schedule work when you are already in control of the times when the work should happen. JobDispatcher is used when you need to schedule some work at some point in time or interval when your app may not even be running.

Related

How to clear unwanted records in Kinvey Database

I am having an Android app and I am planning to use Kinvey Database to store some data.
One of the record in the entry would be having the last used time period.
The last used time period will be set by my app when ever the app is opened.
What basically I am trying to achieve is to run a code at the end of each month and clear all the record whos value of the last used period is more than 10 days.
Can any one please tell me whether it is possible to do this?
The reason for doing this is to use the least Server storage space as they provide only 1 GB/Monthly in the free plan.
What I understand from this...
What basically I am trying to achieve is to run a code at the end of each month and clear all the record whos value of the last used period is more than 10 days.
Can any one please tell me whether it is possible to do this?
... is that you would like to have scheduled code, which will be executed once a month. Please take a further look at the Scheduled Code feature of Kinvey.
https://devcenter.kinvey.com/html5/tutorials/scheduled-code-getting-started
Edit: more information on the topic...
Kinvey Scheduled code allows you to execute one of your custom endpoints on a specific date in the future. It is commonly used to
Aggregate, archive, and cleanup data.
Pull data from a third-party API into Kinvey.
Send out a batch of e-mails or push notifications.
I would not bother describing step-by-step initializing of Scheduled Code, since those steps may change in the future. Please follow the steps from the link above, those should be fine to get you further.

How to get correct universal timestamp in java if the time is set wrong on the computer?

Is there any way to get the results like in this link having wrong date and time set on device? Thank you.
There's a way1 ...
Suppose that you have deliberately set the clock 1 minute slow.
Create a file that contains the number 60,000. When an application wants to find the correct time, it calls System.getTimeMillis() to get what the system thinks the time is. Then reads the number from the file and adds that number to the result of System.getTimeMillis().
Clearly, this is NOT a good idea, but then neither is deliberately setting the system clock incorrectly. (For a start, if the clock is miss-set, then you will have difficulty syncing it with an external time source like an NTP server. That means that your system's clock will drift.)
The problem i am working on is the TOTP algorithm. The thing I was wondering is how would it work if the time on server and the one on the device are not the same.
I see. The answer is that TOTP cannot work if the two clocks are not synchronized to within a small multiple of the timestep.
1 - There's another way too. Write an application that can do some image processing on a picture of a clock to read the time. Then hook this up to your computer's video camera, and point the camera at a cuckoo clock hanging on your wall. Make sure you wind up the clock regularly. If you want the date as well, point a second video camera at your Dilbert desk calendar.

How do I save chronometer elapsed time in android app

I'm developing a sort of parking meter counter app for a few specific locations. The app asks the user where he is (dropdown menu, saves column letter and number, like A6) and then shows a screen with the given location, a timer (chronometer class) counting up from 0 and the price that has to be paid on exit (calculated using elapsed hours * base price).
This all works nicely, until the user or the OS kills the app (task manager or memory management). Then, the next time the user opens the app, he's back at the main menu and his location, time and price has been lost.
I need a way to save all of the user's information and be able to load it up on app restart.
Initially I had thought to save the user's location and the exact time the chronometer started (DateTime.Now() maybe?) to a .txt file in the internal storage so that it would read:
mallname,columnLetter,columnNumber,startTime
This way, if the app is killed, or any time the app is started up from scratch, the MainActivity will first check if a file.txt exists in the app's internal storage, if it does, it immediately starts the lastPage activity, reading the .txt file to pass the values as parameters (thus, the comma separation). If there's no such file, it would just carry on normally. The last page does contain a reset button that would delete the file so that the app can start up normally the next time it's used.
I don't know how efficient this method is, but it's the first thing that came to mind. However, I don't know how to go about this. I have this same exact method programmed in C# for Windows Phone, but I don't know how to translate it into Java for Android. Also, in C# I didn't actually use a chronometer, rather, I had the startTime saved and used a timer that would calculate startTime - DateTime.now() on every tick (every second) and update the textBlock to show this.
Any help would be greatly appreciated.
Usually user data should be saved to a SQLite database, however in your case, since you're talking about a few variables, it'd be much easier for you to save these values in the application's SharedPreferences.
For every value you'd like to save, add this line to your Chronometer's onChronometerTick() method:
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt("your_key", <Your_value>).commit();
This can later (whenever your application recovers from a crash, for example) be retrieved by:
PreferenceManager.getDefaultSharedPreferences(this).getInt("your_key", <Default_value>);
Regarding performance issues, if your Chronometer ticks once every second this should have no effect on your app's performances and is completely acceptable.

Know when phone enters building on android device

I was wondering if there is a way for me to detect if the users device is being "obstructed" by a building or roof of some sort. Im developing a very precise location based app and its KEY that my users get alerted if something is wrong with there GPS or something is getting in the way. Physical object.
EDIT: The app ive created strictly takes snapshots too its not something thats constantly going. Just a quick snapshot.
Not directly. You can try calling LocationManager.getGpsStatus and iterating over the list of satelites every so often and looking for a jump in signal to noise ratio since the last reading. Getting a working algorithm is going to take a good amount of work and testing on a variety of devices with different GPS chips.

Is it possible to modify the time OSCeleton sends a lost_user event/message?

I'm playing around with OSCeleton and Processing and succesfully got to track skeletons and do stuff.
What I'm wondering is if there's any way to change the delay time a "lost_user" message is sent to Processing.
This is taking so long for what I'm trying to achive, since i need to stop tracking a user as soon as he goes away from the screen, so I can accept another user's interaction. (imagine an installation where a lot of people wants to play with).
any help/tips would be really appreciated.
Jon
As far as I can tell from the OSCeleton's source and with my minimal experience with the kinect(I never used OSCeleton), there is no way to modify that code to do that. It seems to be a thing handled even lower, by the driver or by the kinect its self(?).
Yet you need not bind yourself with that, and I would suggest a couple of ways to bypass the problem if I understand properly.
First, the latest drivers and examples should have multi-user support, meaning you can just arrange who is your main user. From what I can tell from the source you do get an osc message in Processing when a new user is detected as well as an ID number. You can put each new user that arrives, into an arrayList and figure out a way to do things without depending on the latest user.
If you are still going for the user-after-user thing though, or I was mistaken about the multi-user support(which is mentioned nowhere in the README), you can check yourself whether a user has left the area. Although you can not get a definitive answer like that you can check for example, whether a specific joint or all joints of a user have moved in the last 10-20 osc messages received. That probably means storing the position of this joint in an 10-20 item array and continuously updating while also doing a check on whether the items are different. If all items in the array are the same, your user has not moved a bit and thus probably should not be taken to account.
Last but not least you can switch to other solutions. The one I used about a year ago was "Synapse for Kinect" which also seems stale now. The latest you can use is a Processing library called SimpleOpenNI which definitively have multi-user tracking and you won't need any intermediary programs running to give you the joints.
I hope this helps

Categories