-1

hello i am new in android so i want to know how to get the the time intervals in android so please help me to find the time intervals in this program?my teacher said in time stamp subtract one time to another time?how to do it?

public class MainActivity extends Activity {

    private Button myLocation;
    private TextView myAddress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myLocation = (Button) findViewById(R.id.location);
        myAddress = (TextView) findViewById(R.id.address);

        myLocation.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                getMyLocationAddress();
            }
        });

    }

    public void getMyLocationAddress() {

        Geocoder geocoder= new Geocoder(this, Locale.ENGLISH);

        try {
            // Place your latitude and longitude
            List<Address> addresses = geocoder.getFromLocation(28.437582, 76.995242, 1);

            if (addresses != null) {
                Address fetchedAddress = addresses.get(0);
                StringBuilder strAddress = new StringBuilder();
                for (int i = 0; i < fetchedAddress.getMaxAddressLineIndex(); i++) {
                    strAddress.append(fetchedAddress.getAddressLine(i)).append("\n");
                }
                myAddress.setText("I am at: " + strAddress.toString());
            } else
              myAddress.setText("No location found..!");
        } catch (IOException e) {
             e.printStackTrace();
             Toast.makeText(getApplicationContext(),"Could not get a address..!",Toast.LENGTH_LONG).show();
        }
    }
}
SilentKiller
  • 6,944
  • 6
  • 40
  • 75

1 Answers1

0

It's very unclear what you are asking but you can get the current time in ms (from 1970) like this:

long time= System.currentTimeMillis();

If get the current time and do the actions of your choice and compare to savedinstance of the time:

long start = long time= System.currentTimeMillis();
//Do method calls
long totalTimeSinceStart = System.currentTimeMillis() - start;
Rawa
  • 13,357
  • 6
  • 39
  • 55