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

  • Home
  • SEARCH
  • 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 8161353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:28:53+00:00 2026-06-06T18:28:53+00:00

I am using service class which gives a call to my inner class that

  • 0

I am using service class which gives a call to my inner class that implements Location Listener which provides me my location details… but I need to do this in regular interval.. I have used Thread with looper but it executes only once Please help

This is my udated answer
Updated answer

    public class MyService extends Service 
{
     String GPS_FILTER = "";
     Thread triggerService;
     LocationListener locationListener;
     LocationManager lm;
     private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1000; // in Meters
     private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000*60; // in Milliseconds
     protected LocationManager locationManager;
     boolean isRunning = true;
     @Override
     public void onCreate() 
     {
           // TODO Auto-generated method stub
           super.onCreate();
           GPS_FILTER = "MyGPSLocation";
//           locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//           locationManager.requestLocationUpdates(
//                   LocationManager.GPS_PROVIDER, 
//                   MINIMUM_TIME_BETWEEN_UPDATES, 
//                   MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
//                   new MyLocationListener());
     }

     @Override
     public void onStart(Intent intent, int startId)
     {
           // TODO Auto-generated method stub
           super.onStart(intent, startId);     
           turnGPSOn();
           Toast.makeText(getApplicationContext(), "Hello1",Toast.LENGTH_LONG).show();
           LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
           locationListener = new MyLocationListener();
           locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MINIMUM_TIME_BETWEEN_UPDATES, 1.0f, locationListener);

     }

     @Override
     public void onDestroy() {
           // TODO Auto-generated method stub
           super.onDestroy();
          // removeGpsListener();
     }

     @Override
     public IBinder onBind(Intent intent) {
           // TODO Auto-generated method stub
           return null;
     }

//     private void removeGpsListener(){
//           try{
//                 lm.removeUpdates(locationManager);
//           }
//           catch(Exception ex){
//                 System.out.println("Exception in GPSService --- "+ex);
//           }
//     }


     private class MyLocationListener implements LocationListener
     {

         public void onLocationChanged(Location location) 
         {
            postdata(location.getLatitude(),location.getLongitude());
             String message = String.format(
                     "New Location \n Longitude: %1$s \n Latitude: %2$s",
                     location.getLongitude(), location.getLatitude()
             );
             Toast.makeText(MyService.this, message, Toast.LENGTH_LONG).show();
             turnGPSOnOff();
         }

         public void onStatusChanged(String s, int i, Bundle b) {
//              Toast.makeText(MyService.this, "Provider status changed",
//                     Toast.LENGTH_LONG).show();
         }

         public void onProviderDisabled(String s) {
//             Toast.makeText(MyService.this,
//                     "Provider disabled by the user. GPS turned off",
//                     Toast.LENGTH_LONG).show();
         }

         public void onProviderEnabled(String s) {
//             Toast.makeText(MyService.this,
//                     "Provider enabled by the user. GPS turned on",
//                     Toast.LENGTH_LONG).show();
         }

     }

also call service using

 Calendar cur_cal = Calendar.getInstance();
   cur_cal.setTimeInMillis(System.currentTimeMillis());
   Intent intent = new Intent(this, MyService.class);
   PendingIntent pintent = PendingIntent.getService(login.this, 0, intent, 0);
   AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
   alarm.setRepeating(AlarmManager.RTC_WAKEUP, cur_cal.getTimeInMillis(), 60*1000, pintent);
  • 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-06T18:28:54+00:00Added an answer on June 6, 2026 at 6:28 pm

    try this…

    TimerTask doAsynchronousTask;
    long timerCall = 5000;  
    final Handler handler = new Handler();  
    Timer timer = new Timer();
    
    public static int times = 0;
    
     // For tracking
    doAsynchronousTask = new TimerTask() {
            @Override
            public void run() {
                handler.post(new Runnable() {
                    public void run() {
                        try {
                            performBackgroundTask.execute();//In this function add your code which you want to  call repeatedly. OR ADD  lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
                             Toast.makeText(getApplicationContext(), "Hello1",Toast.LENGTH_LONG).show();
                             gpsLocationListener = new GpsListener();
                             long minTime = 30000; // 5 sec...
                             float minDistance = 10;
                             lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance, gpsLocationListener);
    
                             Log.d("BGT", "BGT=" + times++);//how many time it called
                        } catch (Exception e) {
                        }
                    }
                });
            }
        };
        timer.schedule(doAsynchronousTask, 0, timerCall);// execute in every 50000 ms
    

    `

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

Sidebar

Related Questions

I need to call a web service to receive a JSON object which I'll
I have several wcf services which are hosted using ServiceHost class. Now , I
I'm trying to build the proxy class for a web service using the wsdl
I have a WCF Service Library (implemented using NH) with one of the class
Hi i am reading inbox using service but i m getting null pointer exception
I'm calling a web service that gives me as an xml response an invalid
I am designing a web service which will call different external web services according
Using DBIx::Class and I have a resultset which needs to be filtered by data
I've created one web service which is of asmx type. And I'm using my
I am using Sectioned List in my activity which extends ListActivity but now as

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.