Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android GPS停止,onPause()_Android_Gps_Location_Onpause - Fatal编程技术网

Android GPS停止,onPause()

Android GPS停止,onPause(),android,gps,location,onpause,Android,Gps,Location,Onpause,在我的应用程序中,当我开始使用GPS时,我无法停止它,无论我是否按下后退或主页按钮,土司都会出现(我在requestLocationUpdate调用中输入0,0以查看它是否这样做) 它表明onPause方法(当我按下back/home按钮进入时)removeUpdates调用不起任何作用。还是别的什么问题?请帮助我,因为在过去的三天里,我一直在解决这个问题。应用程序的逻辑:我按下一个按钮,然后它检查哪个提供者是活动的whatIsEnabled()方法 我的代码是: public class Ma

在我的应用程序中,当我开始使用GPS时,我无法停止它,无论我是否按下后退或主页按钮,土司都会出现(我在requestLocationUpdate调用中输入0,0以查看它是否这样做)

它表明onPause方法(当我按下back/home按钮进入时)removeUpdates调用不起任何作用。还是别的什么问题?请帮助我,因为在过去的三天里,我一直在解决这个问题。应用程序的逻辑:我按下一个按钮,然后它检查哪个提供者是活动的whatIsEnabled()方法

我的代码是:

public class Map extends MapActivity {
private MapView mapView;
private MapController mc;
private GeoPoint p;
private Context context;
private Drawable drawable;
private Bundle instanceState;
private EditText et;
private ImageButton connect, layers, location;
private int i = 1;
//private Settings settings;
private LocationManager locationManager;
private LocationListener locationListener;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    instanceState = savedInstanceState;
    setContentView(R.layout.main);
    context = getApplicationContext();

    //settings = new Settings();

    //to zoom
    mapView = (MapView) findViewById(R.id.mapView);
    mapView.setBuiltInZoomControls(true);

    et = (EditText) findViewById(R.id.address);

    connect = (ImageButton) findViewById(R.id.connect_icon);
    connect.setOnClickListener(connect_button);


    layers = (ImageButton) findViewById(R.id.layers);  
    layers.setOnClickListener(layer_button);

    //locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    //locationListener = new Coordonates(drawable, mapView, Map.this);
    location = (ImageButton) findViewById(R.id.location_icon);
    location.setOnClickListener(location_button);



    //markers
    drawable = this.getResources().getDrawable(R.drawable.blue_pin);

}

private OnClickListener connect_button = new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent myIntent = new Intent(Map.this, Connection.class);
        Map.this.startActivity(myIntent);
    }
};

private OnClickListener layer_button = new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        if(i%2 != 0) {
            mapView.setStreetView(true);
            mapView.setSatellite(false);
        }
        else {
            mapView.setSatellite(true);
            mapView.setStreetView(false);
        }
        i++;
    }
};

private OnClickListener location_button = new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        //registerLocListener();

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationListener = new Coordonates(drawable, mapView, Map.this);

        switch(Settings.whatIsEnabled()) {
        case 1: {
            Toast.makeText(context, "Location services disabled",Toast.LENGTH_LONG).show();
            break;
        }
        case 2: {
            Toast.makeText(context, "Location obtained via GPS satellites",Toast.LENGTH_LONG).show();
            Toast.makeText(context, "Waiting for location",Toast.LENGTH_LONG).show();
            System.out.println("1");
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,locationListener);//50
            if(Coordonates.getLatitude() == 0)  
                Toast.makeText(context, "No GPS signal",Toast.LENGTH_LONG).show();
            System.out.println("2");
            break;
        }
        case 3: {
            Toast.makeText(context, "Location obtained via Wi-Fi/mobile network",Toast.LENGTH_LONG).show();
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);//1000
            if(Coordonates.getLatitude() == 0)  
                Toast.makeText(context, "No Wi-Fi/mobile network signal",Toast.LENGTH_LONG).show();
            break;
        }/*
        case 4: {
            Toast.makeText(context, "Location obtained via the best provider available",Toast.LENGTH_LONG).show();
            locationManager.
            break;
        }*/
        }
    }
};
/*
protected void onResume() {

    super.onResume();
}*/

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    System.out.println("a intrat in onPause()");
    if(locationManager != null) {
        locationManager.removeUpdates(locationListener);
    }
    locationListener = null;
    locationManager = null;
    super.onPause();
}

我开发了一个类似的应用程序,但我把

locationManager.removeUpdates(locationListener)

在获取位置后,在onCreate()方法中,而不是在onPause()中。将其置于onPause()中的问题是,在您离开(暂停)活动时将调用它。因为我没有跟踪用户的移动,所以一旦得到他们的位置,我就会停止侦听器

如果您开发的应用程序的功能与我的不同,那么这可能没有什么用处

祝你好运

您是否在控制台中获得了输出“onPause()中的intrat”?检查控制台并回复