Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.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连接丢失_Android_Gps - Fatal编程技术网

android应用程序切换到新屏幕时GPS连接丢失

android应用程序切换到新屏幕时GPS连接丢失,android,gps,Android,Gps,我正在开发一个android应用程序,它处理谷歌地图和GPS。它是一个显示地图的接近警报应用程序,接受用户的触摸并为该位置设置警报。我添加了一个EditText,以接受用户希望通知的距离目标有多远。但无论用户输入什么,应用程序都将该值视为2km。是因为它使用的是信号塔信息而不是GPS吗?如果有任何教程可以帮助我开发应用程序,请分享。当用户在地图上选择一个位置时,将显示一个新屏幕,让用户输入通知距离。但当应用程序从地图屏幕转到用户输入屏幕时,GPS图标消失。有什么问题吗?这是处理设置警报的部分

我正在开发一个android应用程序,它处理谷歌地图和GPS。它是一个显示地图的接近警报应用程序,接受用户的触摸并为该位置设置警报。我添加了一个EditText,以接受用户希望通知的距离目标有多远。但无论用户输入什么,应用程序都将该值视为2km。是因为它使用的是信号塔信息而不是GPS吗?如果有任何教程可以帮助我开发应用程序,请分享。当用户在地图上选择一个位置时,将显示一个新屏幕,让用户输入通知距离。但当应用程序从地图屏幕转到用户输入屏幕时,GPS图标消失。有什么问题吗?这是处理设置警报的部分

    mSetAlarm.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Get the distance from the shared preferences
            SharedPreferences preferences = PreferenceManager
                .getDefaultSharedPreferences(getBaseContext());

            String distanceStr = preferences.getString("distance", "0");
            double distance = Double.parseDouble(distanceStr);

            LocationManager locationManager = (LocationManager) getBaseContext()
                .getSystemService(Context.LOCATION_SERVICE);

            AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
            Intent intent = new Intent(LocationInfoActivity.this,
                MyBroadcastReceiver.class);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(
                getBaseContext().getApplicationContext(), 234324243,
                intent, PendingIntent.FLAG_UPDATE_CURRENT);

            MyLocationListener locationListener = new MyLocationListener(
                locationManager, preferences, alarmManager,
                pendingIntent);

            if (distance < Double.parseDouble(i)) {
                alarmManager.set(AlarmManager.RTC_WAKEUP, System
                        .currentTimeMillis(), pendingIntent);
                locationManager.removeUpdates(locationListener);
            } else if (distance < 4.0) {
                WakeMeUtill.requestLocationUpdates(locationManager, 0, 0,
                        locationListener);
            } else {
                double quaterDistance = (distance * 3) / 4;
                WakeMeUtill.requestLocationUpdates(locationManager, 0,
                        (float) quaterDistance * 1000, locationListener);
            }
        }
    });
}
mSetAlarm.setOnClickListener(新的OnClickListener(){
公共void onClick(视图v){
//获取与共享首选项的距离
SharedReferences首选项=首选项管理器
.GetDefaultSharedReferences(getBaseContext());
String distconsers=preferences.getString(“距离”,“0”);
双距离=double.parseDouble(distconsers);
LocationManager LocationManager=(LocationManager)getBaseContext()
.getSystemService(Context.LOCATION\u服务);
AlarmManager AlarmManager=(AlarmManager)getSystemService(报警服务);
意向意向=新意向(LocationInfoActivity.this,
MyBroadcastReceiver.class);
PendingIntent PendingIntent=PendingIntent.getBroadcast(
getBaseContext().getApplicationContext(),2343243,
意向、挂起内容、标志(更新当前);
MyLocationListener locationListener=新建MyLocationListener(
locationManager、首选项、alarmManager、,
悬挂式);
if(距离
可能在您的代码中,您在onPause()方法中编写了这一行

请检查您的密码


如果这不是问题,请分享更多细节。

您使用的是哪种设备/Android版本?
onPause()
{
   gpsLocationManager.removeupdates() 
}