0

I can start a broadcast receiver by this code which detects my location update

Intent intent = new Intent(
                        LocationChangedReciever.ACTION_LOCATION_CHANGED);
                LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                long minTime = 1000; // This should probably be fairly long
                float minDistance = 1; // This should probably be fairly big
                String provider = "gps"; // GPS_PROVIDER or NETWORK_PROVIDER

                PendingIntent launchIntent = PendingIntent.getBroadcast(this,
                        0, intent, 0);
                manager.requestLocationUpdates(provider, minTime, minDistance,
                        launchIntent);

I did it in one my button click, but once I click that button the receiver starts to work for all the time, but i have a stop button which will disable the receiver, but I couldnt do it, this receiver works unless I uninstall it, any help?

4

1 に答える 1

1

コールしremoveUpdates(launchIntent)ます。これが機能するには、remove 呼び出し用に保存されたインテントへの参照を保持する必要があります。

于 2013-02-24T18:17:28.137 に答える