0

I want to track the usage of my app. Every time it's open on the device it sets a String that it's open for that day. If the user closes the app and opens it again in the same day, new value isn't send to server. So, I'm clean on this part. The part that is unknown to me is how can I test when the app is open. One solution is when the app goes on my home activity, but in that case if someone opens something and press back it will process some data as the app is open for the first time, so it's not the best solution.

Claire
  • 60
  • 11

3 Answers3

0

You could create a custom application like so :

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // Put your code here 
    }
}

and in your manifest do :

<application
        android:name=".MyApplication"
        <!-- other fields -->

but if you want a better solution you could use a third party analytics API

A.Edwar
  • 341
  • 3
  • 12
  • As you can see in my question, my solution is something like that, I was asking for third party libraries or APIs, even Android functions that do that. If not, I'm going to stick to my original plan. – Claire Jun 01 '17 at 14:59
  • I think google analytics or firebase analytics will do that. – A.Edwar Jun 01 '17 at 15:02
0

When Activity.onCreate() is called, it sends something to the server. Later the server removes duplicates. Fini....

  • That's too much data for nothing, really, that's kinda my solution now without the "sending everything to server" part. Why should I send all the data to server? It's stupid. My app can work offline for days and then send a bunch of data to server for nothing. – Claire Jun 01 '17 at 14:56
  • Did you check how often onCreate() is called? –  Jun 03 '17 at 18:44
0

You can do the following:

  1. Check if string is send for current day by checking the TIMESTAMP stored in SharedPreferences.
  2. If not then, send the string.
  3. Then store the current TIMESTAMP to SharedPreferences.
Cijo
  • 2,726
  • 1
  • 14
  • 24
  • My current solution is with Store (kinda same) but I want another solution. That's why I was asking is there is an Android function or library that does that. – Claire Jun 01 '17 at 14:57