Jump to content

Recommended Posts

Posted
MAIN CLASS:
 
public final class MainActivity extends Activity {
private void sendSmsWithAddress(String troubleType, LatLng coordinates, String address) {
        double lat = coordinates.latitude;
        double lng = coordinates.longitude;
        sendSmsToContacts(troubleType + "!\n" + address + "\nhttp://ubersafe.com/" + lat + "/" + lng);
    }
}
 

NEW CLASS:
 
public final class TroubleRepeater {
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
        Runnable CoordinatesFinder = new Runnable() {
            public void run()
            {
                  private void sendSmsWithCoordinates(String troubleType, LatLng coordinates) {
                double lat = coordinates.latitude;
                double lng = coordinates.longitude;
                sendSmsToContacts(troubleType + "! Coordinates:\n(" + lat + ", " + lng + ")\nhttp://ubersafe.com/" + lat + "/" + lng);
            }
            }
        };
        ScheduledFuture result = executor.scheduleAtFixedRate(CoordinatesFinder, 2, 30, TimeUnit.SECONDS);
}
 
 
 

I need in main class action repeat x times. I am trying to delete from main class this action and add him to new class (check my repeater, it works good or not)
 and i need call it in main class, how i can do it?

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..