So I'm writing a fitness application for android. I'm using the Google fit API to count the steps.
I'm using the Recording API to count the steps when the app is in the background. Once the app is in the foreground I'm fetching the steps count with the History API to show it on the screen.
What happens is that the count is not correct. There is a delay until you get the correct and updated count.
To be more specific no data is being lost. I guess that the Recording API is updating with a specific time interval.
I'm also using the Sensors API to show the real count on my Activity when it is running. So what happens is that for example you see 300 steps in your screen (real time data). Close the app, open it again and then for the next minute you see 250 steps for example. And only after some time the History API catches the correct data and shows 300 again.
Has anyone found a way through this issue?
Thank you and sorry for the long text!
Your are right. Recording API takes some time for update. There is two way that came to my mind.
always get steps by History API. I mean when activity is running just increase the checking rate of History API. Advantage of this is though it is taking some time, user always the same count.
another way is bit more complex. store your Sensors Step count with time & apply some logic whether or not you need to add & show this to user.
Sorry for the long text.
Related
I am making a mobile application and I need to have the current time. However, I don't want to depend on the user's phone time since it can be changed to whatever they want. Is it a good practice to fetch from a server its local time every minute or similar interval?
P.S: The app will use the time to show if a shop is open or closed so I don't mind about different timezones, I only need the time in the server's timezone.
Depending on the need of the application. If your application would require a connection from the internet, then yes. You can also put that in case there is an issue catching the online time, you can just take the user's time.
From personal experience I never had issues that the user would want to change their phone time, but there have been a few exception.
To use server times is fine. But based on that making decisions on data (shop open/not) is not a good practice. Whenever you make an api call, get the status if its closed or not. This will avoid user side data issues
If you want to show this information on a single shop page, fetch the time difference between current time and closing time from the server. This will help you to maintain the status on app side. this should not be for a very long time. You can use this solution if the difference is less than 10 or 15 mins.
Google Analytics (using iOS SDK version 3.14 and it's built in sessions tracking) is reporting a significant percentage of app sessions as 1 second.
Maybe users are launching an app to view a page and (effectively) then instantly leaving the app, but that seems unlikely (that it should continue as the top use case. You think such users would stop using or uninstall.)
Initially I suspected this was related to "background fetch" but when I look at a prior incarnation of the application (that did not have background fetch enabled or used) I still see these (seemingly) bogus sessions also. That application (pre iOS9) had no universal links.
The (obvious) reason I don't want to see these sessions (especially if from automated action not user action) is it removes all value of "user behavior"; i.e. loyalty, recency and skews "average session length". These are the main reasons I want to use GA, i.e. to see if folks are using it more/valuing it more.
My questions:
What might these sessions be caused by? Are they bogus?
If bogus, how can I stop them?
Can I ensure new "background fetch" code doesn't somehow trigger them?
Some things I've considered / looked into:
I am seeing a similarly large set of "short sessions" on an Android application (this application's peer) and again with extremely high numbers. I've been wondering if this was a result of a web searches & site links, with those site links automatically loading the app, and the a (very) quick user "move on". (Universal linking is something the new iOS application is working towards, but doesn't see much of yet.) Given it is not that on iOS I am starting to doubt that it is that on Android.
There is a "optOut" option on GA. That feels like a sledgehammer solution to this walnut problem. It is also a persistent setting, which feels risky to use for a transient situation. I could attempt to toggle it at applicationDidEnterBackground / applicationDidBecomeActive (and will if it is deemed the solution) but worry it could have negative side-effects.
One can have multiple trackers. I am planning to attempt one for human foreground activity and one for background operations (which might allow time /event tracking when in background, w/o impacting human user tracking numbers. That said, I don't know / believe this is the cause of the bogus sessions. )
One can manage sessions manually and also customize the sessions interval timeout, but I don't see why this application should need any custom behavior. It is a normal application.
The application isn't reporting crash totals to match these numbers; it is a generally well liked 4/5 star app w/ few crashes.
Google Analytics measures duration as the time between interactions.
This means that in order to be able to measure duration, Google Analytics needs a minimum of two interactions to measure between. But they still need to collect data on one-interaction Sessions, and from the reporting perspective, every session starts the same - with an interaction. It's just that some don't go any further. To account for this, Google Analytics keeps a running total of Session duration.
When a user first interacts, that total is set to 0.
31 seconds later, they interact again. That total is updated to 31 seconds.
10 seconds later, they interact a third time. Total is now 41 seconds.
35 seconds later, they quit. This is not measurable, and hence not an interaction. Google Analytics waits faithfully for 30 minutes, before deciding that they aren't coming back.
Your total Session Duration is recorded as 41 seconds, as that was the last point at which you checked in. There's no way of knowing that you stuck around an extra 35 seconds.
This isn't an issue if you looked at 4 or 5 pages, but if you had only looked at 1 page, we would have been left with a Session Duration of 0. This is what happens with every 'Bounce'; every Session with only one interaction is measured '0' seconds long.
Throw into that a handful of people who interacted 8 or 9 seconds later, and you have an average of 1 second for the '0 - 10' category.
Turns out the problem was inside the Google Analytics SDK. A new version has been posted:
[Google Analytics SDK issue with short sessions][1]
My code was working fine initially, then All of a sudden I'm not able to display posters on my app. I'm getting this particular error.
I've removed almost all while(true) loops. Please help.
You are probably making too many API requests.
From the TMDB.org FAQ:
We currently rate limit requests to 30 requests every 10 seconds.
You should make sure your app never uses more than that. How you implement this is up to you, but you could keep track of a request counter that:
decrements every time you make a request
resets to 30 or so every ten seconds
only allows requests to continue if it is positive
In general, you should try to query the API as little as possible: cache results in your app as much as you can.
I just made an app where a friend list is being updated in real time depending on if you get blocked or deleted by one of your friends, so I refresh the list on the screen. However, I was wondering what would be appropriate as the time interval for updates using threads? right now I am using 1 second but I think it's a bit exaggerated.
I would have it as user defined. If you set a default time that is unchangeable, some users may think it is running the thread too often. They may also think your app is causing bad battery life. Just have a few options like Twitter or Facebook. Something like 1,5,10,30,60,180,etc.
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.