1

I am trying to figure out the individual App process elapsed time that is running in an Android device by core. Whereby, the method implementation calculates and log the individual running App process elapsed time that the individual app in the android device from the proc.Id that it has detected. Very much like Windows or Mac Os, Activity Manager/ Task Manager, it shows the elapsed time of each running program.

I have tried researching from http://www.widecodes.com/0HxgXjkWXg/how-to-find-out-the-runningstart-time-of-android-application.html, however when implemented, the following 3 code lines' functional process doesn't seem correct when integrated with my Android Studio code block:

final int tckName = Class.forName("libcore.io.OsConstants").getField("_SC_CLK_TCK").getInt(null);
final Object os = Class.forName("libcore.io.Libcore").getField("os").get(null);
final long tck = (Long)os.getClass().getMethod("sysconf", Integer.TYPE).invoke(os, tckName);

Secondly, I have managed to find out that "Sigar" can be used to fetch process time from unable to fetch process time using sigar, however I am unable to implement that function into Android Studio as it is not present within Android Studio lib.

Furthermore, I do understand on the method of using the following:

Process_startTime = System.nanoTime();
Process_endTime = System.nanoTime();
Process_elapsed = Process_endTime-Process_startTime;

This method is only applicable for the entire App or System, I do need to get the individual running App process elapsed time in the android device, hence I do not think the above System.nanoTime() Timer method is the correct way of doing it.

Therefore, I would like to ask for your help on how to fetch each individual running app process in Android. Thank you.

I have paste the code snippet for your perusal:

for (int i=0; i < runningProcesses.size(); i++) {

        jsonArray.put(runningProcesses.get(i).processName);

        try {
            android.os.Process currentproc = new Process();
            currentproc.getUidForName(runningProcesses.get(i).processName);
            System.out.println("******RobotService.java: processName******"+ currentproc);


            CurrentProcTime = getStartTime(runningProcesses.get(i).pid);
            System.out.println("******RobotService.java: CurrentProcTime******"+ CurrentProcTime);



            ...

            jsonArrayData.put(AppElapsedTime);
        //System.out.println("runningProcesses:processName:>>" + runningProcesses.get(i).processName +" " + dt_hr + "<<");

        jsonArrayData.put(AppElapsedTime);

        } catch (IOException e) {
            e.printStackTrace();
        }catch (OutOfMemoryError e){
            e.printStackTrace();
        }
Community
  • 1
  • 1
developer
  • 61
  • 2
  • 10

0 Answers0