Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8482673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:52:47+00:00 2026-06-10T19:52:47+00:00

public class LocUpdator extends Activity implements LocationListener { private TextView latituteField; private TextView longitudeField;

  • 0
public class LocUpdator extends Activity implements LocationListener {

 private TextView latituteField;
  private TextView longitudeField;
  private LocationManager locationManager;
  private LocationManager service;
  private String provider;


/** Called when the activity is first created. */

  @Override
  public void onStart() {
    super.onStart();
    //setContentView(R.layout.main);


    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the locatioin provider -> use
    // default
    service = (LocationManager) getSystemService(LOCATION_SERVICE);
    boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER);

            // Check if enabled and if not send user to the GSP settings
            // Better solution would be to display a dialog and suggesting to 
            // go to the settings
            if (!enabled) {
              Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
              startActivity(intent);
            } 
    Criteria criteria = new Criteria();
    //criteria.setAccuracy(Criteria.ACCURACY_FINE);
    //criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
    provider = locationManager.getBestProvider(criteria,true);
    Location location = locationManager.getLastKnownLocation(provider);

    // Initialize the location fields
    if (location != null) {
      System.out.println("Provider " + provider + " has been selected.");
      Toast.makeText(this, "Provider " + provider + " has been selected." ,Toast.LENGTH_SHORT).show();
      onLocationChanged(location);
    } else {
      latituteField.setText("Is GPS ON ?");
      longitudeField.setText("Sorry! No GPS");
    }
  }

  /* Request updates at startup */
  @Override
  protected void onResume() {
    super.onResume();
    locationManager.requestLocationUpdates(provider, 400, 1, this);
  }

  /* Remove the locationlistener updates when Activity is paused */
  @Override
  protected void onPause() {
    super.onPause();
    locationManager.removeUpdates(this);
  }

  @Override
  public void onLocationChanged(Location location) {
    double lat = (double) (location.getLatitude());
    double lng = (double) (location.getLongitude());
    //Http Post method to send data to srver Php document
    Toast.makeText(this, "Transfered location: "+lat+" "+lng ,Toast.LENGTH_SHORT).show();
    Toast.makeText(this, "Currently using " + provider + " technology." ,Toast.LENGTH_SHORT).show();
    //latituteField.setText(String.valueOf(lat));
    //longitudeField.setText(String.valueOf(lng));
  }

  @Override
  public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub
      Toast.makeText(this, "Location Change Notification !!" ,Toast.LENGTH_SHORT).show();


  }

  @Override
  public void onProviderEnabled(String provider) {
    Toast.makeText(this, "Enabled new provider " + provider,
        Toast.LENGTH_SHORT).show();

  }

  @Override
  public void onProviderDisabled(String provider) {
    Toast.makeText(this, "Disabled provider " + provider,
        Toast.LENGTH_SHORT).show();
  }
} 

I want this activity of mine to be started at a fixed interval of time , I tried the Alarm Manager and BroadcastReciever but … I cannot Find Any way to start this from the broadcast receiver…

public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    //Toast.makeText(context, "Location Cordinates Updating!!!!.",Toast.LENGTH_LONG).show();

    Toast.makeText(context, "Current Location :",Toast.LENGTH_LONG).show();
    Intent startIntent = new Intent(context, LocUpdator.class);
    context.startActivity(startIntent);
    startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Above is the BroadcastReciever

The AlarmActivity is below

public class AlarmActivity extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

public void startAlert(View view) {
    //EditText text = (EditText) findViewById(R.id.time);
    int i = 20;//Integer.parseInt(text.getText().toString());
    //int i= 10;
    Calendar calendar = Calendar.getInstance(); 
    calendar.setTimeInMillis(System.currentTimeMillis()); 
    Intent intent = new Intent(this, MyBroadcastReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(
            this.getApplicationContext(), 234324243, intent, 0);

    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ (i * 1000), pendingIntent);
    //long timerInterval= i*1000;
    //alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), timerInterval, pendingIntent); 
    //finish();  
    Toast.makeText(this, "DB Update Interval set as " + i + " seconds",
            Toast.LENGTH_LONG).show();
}

}

Please Help Me out here 🙂


The log Cat Error is below

09-10 09:50:15.368: E/AndroidRuntime(671): FATAL EXCEPTION: main
09-10 09:50:15.368: E/AndroidRuntime(671): java.lang.RuntimeException: Unable to start activity ComponentInfo{twin.geolocator/twin.geolocator.insideActivity}: java.lang.IllegalArgumentException: provider==null
09-10 09:50:15.368: E/AndroidRuntime(671):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
09-10 09:50:15.368: E/AndroidRuntime(671):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-10 09:50:15.368: E/AndroidRuntime(671):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-10 09:50:15.368: E/AndroidRuntime(671):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-10 09:50:15.368: E/AndroidRuntime(671):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 09:50:15.368: E/AndroidRuntime(671):  at android.os.Looper.loop(Looper.java:137)
09-10 09:50:15.368: E/AndroidRuntime(671):  at android.app.ActivityThread.main(ActivityThread.java:4745)
09-10 09:50:15.368: E/AndroidRuntime(671):  at java.lang.reflect.Method.invokeNative(Native Method)
09-10 09:50:15.368: E/AndroidRuntime(671):  at java.lang.reflect.Method.invoke(Method.java:511)
09-10 09:50:15.368: E/AndroidRuntime(671):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-10 09:50:15.368: E/AndroidRuntime(671):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-10 09:50:15.368: E/AndroidRuntime(671):  at dalvik.system.NativeStart.main(Native Method)
09-10 09:50:15.368: E/AndroidRuntime(671): Caused by: java.lang.IllegalArgumentException: provider==null
09-10 09:50:15.368: E/AndroidRuntime(671):  at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1153)
09-10 09:50:15.368: E/AndroidRuntime(671):  at twin.geolocator.insideActivity.onCreate(insideActivity.java:32)
09-10 09:50:15.368: E/AndroidRuntime(671):  at android.app.Activity.performCreate(Activity.java:5008)
09-10 09:50:15.368: E/AndroidRuntime(671):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-10 09:50:15.368: E/AndroidRuntime(671):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
09-10 09:50:15.368: E/AndroidRuntime(671):  ... 11 more

public class insideActivity extends Activity implements LocationListener{

private LocationManager locationManager;
private String provider;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
   // setContentView(R.layout.main);

    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the locatioin provider -> use
    // default
    Criteria c = new Criteria();
    c.setAccuracy(Criteria.ACCURACY_FINE);
    c.setAltitudeRequired(false);
    c.setBearingRequired(false);
    c.setSpeedRequired(false);
    c.setCostAllowed(true);
    c.setPowerRequirement(Criteria.POWER_HIGH);
    provider = locationManager.getBestProvider(c,true);
    Location location = locationManager.getLastKnownLocation(provider);

    // Initialize the location fields
    if (location != null) {
      System.out.println("Provider " + provider + " has been selected.");
      onLocationChanged(location);
    } else {
      Log.d("Location not available", "inside");
      Log.d("Location not available", "inside ");
    }
    Log.d("Inside onCreate", "1");
  }


@Override
public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub
    Log.d("Inside onLocationChanged", "2");


}

@Override
public void onProviderDisabled(String arg2) {
    // TODO Auto-generated method stub
    Log.d("Inside onProviderDisabled", "3");

}

@Override
public void onProviderEnabled(String arg3) {
    // TODO Auto-generated method stub
    Log.d("Inside onProviderEnabled", "4");
}

@Override
public void onStatusChanged(String arg1, int status, Bundle extras) {
    // TODO Auto-generated method stub
    Log.d("onStatusChanged", "");
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:52:49+00:00Added an answer on June 10, 2026 at 7:52 pm

    Read my comment and then use this for delay…

    For a repeating task:

    new Timer().scheduleAtFixedRate(task, after, interval);
    

    For a single run of a task:

    new Timer().schedule(task, after);
    

    task being the method to be executed
    after the time to initial execution
    (interval the time for repeating the execution)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class MCQSample extends Activity implements OnClickListener{ TextView title; String gotBread; RadioGroup AnswerRG; int
public class SaveData extends Activity implements OnClickListener { private DataManipulator dh; static final int
public class FBPost extends Service{ private Bundle params = new Bundle(); private String userID=;
public class CheckedTextView extends TextView implements Checkable { private boolean mChecked; private int mCheckMarkResource;
public class BobDatabase extends SQLiteOpenHelper{ private static final String DATABASE_NAME = bob.db; private static
public class Browser1Activity extends Activity { TextView url; WebView ourBrow; @Override protected void onCreate(Bundle
public class PackageTabActivity extends ListActivity{ HashMap<String,Object> hm ; ArrayList<HashMap<String,Object>> applistwithicon ; private static final
public class SuperUser extends User implements Serializable{ private static final long serialVersionUID = 1L;
public class Prerequisites { private class Course implements Comparator<Course> { public String name; public
public class tryAnimActivity extends Activity { /** * The thread to process splash screen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.