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 8066659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:04:43+00:00 2026-06-05T12:04:43+00:00

hi i am doing a application based on gps,i use gps as service for

  • 0

hi i am doing a application based on gps,i use gps as service for my project ,when gps is turn on it show the location correctly and application runs fine ,but after that i exit from my app completely and when the gps turned off the it shows crash message.which mean even if l leave or exit my app the service class is still running ,and also app get crash if i turn off gps when app is running ,but if i did not turn of gps it work fine.Now how can i solve this problem. i will show my service class used for gps

public class Gps_Service extends Service {

TextView txtv;
List<Address> myList;
String addressStr;
LocationManager lm;
LocationListener ll;
SQLiteDatabase DiaryDB = null;

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}
@Override
public void onCreate() {
    super.onCreate();
    System.out.println("@@@@@@@@@@@ serviceOnCreate");
//      Toast.makeText(this, "GPS Service started(Diary)", Toast.LENGTH_LONG).show();       

    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    ll = new mylocationlistener();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);

}

@Override
public void onDestroy() {
    super.onDestroy();

//      Toast.makeText(this, "GPS Service Destroyed(Diary)", Toast.LENGTH_LONG).show();

    lm.removeUpdates(ll);
    System.out.println("@@@@@@@@@@@ inside ONDESTROY GPS listener removed");
}

 @Override
    public int onStartCommand(Intent intent, int flags, int startId) 
    {
        Log.v("StartServiceAtBoot", "StartAtBootService -- onStartCommand()");          
//          Toast.makeText(this, "Service started", Toast.LENGTH_LONG).show();
        // We want this service to continue running until it is explicitly
        // stopped, so return sticky.
        return START_STICKY;
    }

 private class mylocationlistener implements LocationListener
    {

        public void onLocationChanged(Location location) 
        {
            if (location != null) {
                Geocoder myLocation = new Geocoder(Gps_Service.this, Locale.getDefault());
//                  Toast.makeText(MyService.this,location.getLatitude() + "       " + location.getLongitude()   +"\n",Toast.LENGTH_LONG).show();
//                  DiaryDB = MyService.this.openOrCreateDatabase("DIARY_DATABASE", MODE_PRIVATE, null);
//                  DiaryDB.execSQL("INSERT INTO Locations(LATITUDE, LONGITUDE) VALUES('"   +location.getLatitude()+"','"+location.getLongitude()+"')");
//                  DiaryDB.close();
            //  ParseTweetsActivity.latitude  = ""+location.getLatitude();
                //ParseTweetsActivity.longitude = ""+location.getLongitude();
                AndroidGoogleMapsActivity.lats   = Double.parseDouble(""+location.getLatitude());
                AndroidGoogleMapsActivity.longt = Double.parseDouble(""+location.getLongitude());
            Advertiser_get_direction.latitudefrom = Double.parseDouble(""+location.getLongitude());
                Advertiser_get_direction.longtitudefrom = Double.parseDouble(""+location.getLongitude());

                AndroidGoogleMapsActivity.longt = Double.parseDouble(""+location.getLongitude());
                System.out.println("saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+AndroidGoogleMapsActivity.lats);
          //    ParseTweetsActivity.load();
                try 
                {
                    myList = myLocation.getFromLocation(location.getLatitude(),location.getLongitude(), 1);

                } catch (IOException e) {

                    e.printStackTrace();
                }

                if(myList!=null)
                {

                    Address address = (Address) myList.get(0);

                    addressStr = "";
                    addressStr += address.getAddressLine(0) + "\n";
                    addressStr += address.getAddressLine(1) + "\n";
                    addressStr += "Country name  "+address.getCountryName() + "\n";
                    addressStr += "Locality      "+address.getLocality() + "\n";
                    addressStr += "Country code  "+address.getCountryCode() + "\n";
                    addressStr += "Admin Area    "+address.getAdminArea() + "\n";
                    addressStr += "SubAdmin Area "+address.getSubAdminArea() + "\n";
                    addressStr += "PostalCode    "+address.getPostalCode() + "\n";

                //  txtv.append(location.getLatitude() + "    " + location.getLongitude() +"\n");
                //  txtv.append(addressStr+"\n");
                    System.out.println(location.getLatitude() + "    " + location.getLongitude() +"\n");
                    lm.removeUpdates(ll);
                }
            }
        }
        public void onProviderDisabled(String provider) 
        {
//              Toast.makeText(MyService.this,"Provider Disabled",Toast.LENGTH_LONG).show();
            txtv.setText("");
        }
        public void onProviderEnabled(String provider)
        {
//              Toast.makeText(MyService.this,"Provider Enabled.....",Toast.LENGTH_LONG).show();
        }
        public void onStatusChanged(String provider, int status, Bundle extras)
        {
        }
   }

}
  • 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-05T12:04:44+00:00Added an answer on June 5, 2026 at 12:04 pm

    You have declared a TextView within your Service. That’s not good. TextView is a UI component and doesn’t belong on the service.

    In your onProviderDisabled() method, you call txtv.setText(""); which will probably crash because txtv is null. This is probably why your app is crashing when you disable GPS.

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

Sidebar

Related Questions

Created a Location alarm based app. Everything is working fine on emulator. But the
Doing my first SL4 MVVM RIA based application and i ran into the following
I'm doing a navigation based application. Let me explain a little bit about the
I have a problem here. Right now I'm doing my Web Based Application, my
I am doing an application which is of SingleView BASED Application,where i have many
I'm witting an application based on a server and various client but I'm having
I am preloading all my assets before I start a JS-based application doing: assets
I am doing a map based application in iphone. I get my data(address) from
Greetings, I have a view based application project where I have created an NSObject
I am doing a project on criminal tracking using gps and i am not

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.