Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Q] Measure time to access hardware

OP vaern

16th May 2014, 01:22 AM   |  #1  
OP Junior Member
Thanks Meter: 0
 
2 posts
Join Date:Joined: May 2014
Hello!
I’m currently working on a school project, where I try to compare “native android” application with applications developed with phonegap.

Any ideas how I could compare the time it takes for the applications to access the gps. In phonegap I have done the following ( not even sure if is the correct way to do it…):


function getGps(){
var onSuccessr = function (acceleration){
date2 = new Date().getTime();
alert(“time:” (date2 – date1));

}
function onErrorr() {
alert('onError!');

}
date1= new Date().getTime();
navigator.accelerometer.getCurrentAcceleration(onS uccessr, onErrorr);
}

How to do something similar in “native android?
16th May 2014, 01:16 PM   |  #2  
SimplicityApks's Avatar
Senior Member
Flag Aachen
Thanks Meter: 337
 
347 posts
Join Date:Joined: May 2013
More
Quote:
Originally Posted by vaern

Hello!
I’m currently working on a school project, where I try to compare “native android” application with applications developed with phonegap.

Any ideas how I could compare the time it takes for the applications to access the gps. In phonegap I have done the following ( not even sure if is the correct way to do it…):


function getGps(){
var onSuccessr = function (acceleration){
date2 = new Date().getTime();
alert(“time:” (date2 – date1));

}
function onErrorr() {
alert('onError!');

}
date1= new Date().getTime();
navigator.accelerometer.getCurrentAcceleration(onS uccessr, onErrorr);
}

How to do something similar in “native android?

I don't know what language phonegap is using, but from what I see you access the accelerometer and not the gps...
To measure the time between two events, just save the System.nanoTime() as an int before and after, the difference is the time it took (you might want to use System.currentTimeMillis() instead.

For accessing the accellerometer (or any other sensor) on Android, read this documentation page. Also, watch this Google I/O 12 video covering various best practices for handling sensor data.
The Following User Says Thank You to SimplicityApks For This Useful Post: [ View ]
16th May 2014, 05:00 PM   |  #3  
OP Junior Member
Thanks Meter: 0
 
2 posts
Join Date:Joined: May 2014
Thanks for the reply!

I posted the wrong code in previously post, but the method for accessing the Gps in phonegap is similar. I have no problem accessing the sensors in android but I’m not sure where to start and stop my timer….

Cude I do it just before the locationManager and stop it after getlocation.latitude ? or is it some strange asynchrony method?

public void gps(){
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION _SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVID ER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
out.setText("lat" + latitude);


//
}
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes