0

how can I get my application uptime?

I found this: https://stackoverflow.com/a/6431668/3973591

But i have this error:

D/Error: ERR: file=BaseDexClassLoader.java
D/Error: ERR: class=dalvik.system.BaseDexClassLoader
D/Error: ERR: method=findClass line=56
D/Error: ERR: stack=java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/ManagementFactory;

Can you help me?

Or do you have another solution?

Roham Rafii
  • 2,793
  • 7
  • 34
  • 44

1 Answers1

4

how i can get my application uptime ?

"Uptime" does not really have a lot of meaning in Android. But, you are welcome to:

  • Create a subclass of Application
  • Override onCreate() and make note of the current time (e.g., SystemClock.elapsedRealtime())
  • Register that custom Application subclass in the manifest, via android:name on the <application> element

Then, your process' uptime is the current time minus the value saved in onCreate().

i found this :https://stackoverflow.com/a/6431668/3973591

That code principally is for Java servers, and that class does not exist on Android.

Community
  • 1
  • 1
CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367
  • Thank you for your quick response. Already i have Application. Also i think about this. But only we have this solution ? Android does not give you uptime ? –  Dec 08 '16 at 14:03
  • 1
    @Hasan: "Android does not give you uptime ?" -- not that I can think of. Again, it is not a useful metric on Android IMHO. Processes are supposed to come and go as needed. – CommonsWare Dec 08 '16 at 14:04
  • 3
    There can be a need to track and test uptime, for digital signage or kiosk applications where a single Application is long running – Ian Butler Nov 16 '18 at 04:48