Search code examples
androidandroid-activityparallel-processingchronometer

How to make android activity run in parallel


I have two class, one is an activity that can handle Chronometer, another is handle LocationListener.I want to run them together to use stopwatch and to get changed location.

Anyone have any samples or suggestions ? Thanks

Addition: Sorry for the confuse question. I just need to know how to make chronometer run while keeping location that changed.


Solution

  • Well, you could use the LocationListener to add Location to an array every time it is changed to keep track of location.

    Example:

    public class MyClass implements LocationListener{
        private static List<Location> locationList = new ArrayList<Location>();
        @Override
        onLocationChanged(Location location){
            locationList.add(location);
        }
    }
    

    Then you could use System.getTimeMillis() (or something akin) when you want to get the start time, and the same method when you want to get the end time. Just subtract the two to get the time difference and how long it took.