Naheed Sultana
Naheed Sultana

Reputation: 354

Get Android App Start Time in a non-activity class

I want to get the start datetime of the android application. The simplest way to do is to note the current time in the onCreate of activity class, but my issue is that I am creating an android library with some utility functions. I want to find out the start datetime of end user application (that is using the library) within the library itself. I don't want to bound the app developer to note down the start time in the onCreate method and pass to the library method.

Considering this scenario, is there any way to do this?

Upvotes: 1

Views: 777

Answers (2)

dishooom
dishooom

Reputation: 498

How about writing a public method( like getStartDateTime() ) in your library to determine the launchtime in your library, and invoking it from the application class of your main application.

By specifying application class name in your AndroidManifest.xml's tag, the application class will be instantiated for you when the process for your application/package is created, which will in turn invoke the getStartDateTime() in your library.

Upvotes: 0

mttdbrd
mttdbrd

Reputation: 1831

getElapsedCpuTime() in android.os.Process should give you what you want:

http://developer.android.com/reference/android/os/Process.html#getElapsedCpuTime()

It's a static method that should by default return the elapsed cpu time for the calling process.

Upvotes: 1

Related Questions