GPS 코드를 사용하는 간단한 안드로이드 응용 프로그램에 문제가 있습니다.토스트가 화면에서 사라지지 않습니다.
내 클래스 MyLocationListener는 LocationListener를 구현하고, 정적 메서드 호출이 :
String strText ="My current location is: " + "Latitude = " + location.getLatitude() + " Longitude= " + location.getLongitude();
Toast.makeText(GpsModule.cont, strText, Toast.LENGTH_SHORT).show();
문제는이 문자열을 표시로됩니다. 그것은 나타나고 끝나지 않습니다. 주 메뉴에서 뒤로 버튼을 누르면 응용 프로그램을 닫을 때도 끊임없이 표시됩니다. 어떤 단서? 이 문제를 어떻게 해결할 수 있습니까?
GpsModule 등급 :
public class GpsModule extends Activity {
public static Context cont;
//public static WebView position;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.gps);
cont = getApplicationContext();
//position = new WebView(cont);
//position = (WebView) findViewById(R.layout.gps);
//position.getSettings().setJavaScriptEnabled(true);
LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
LocationListener locListener = new MyLocationListener();
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
}
MyLocationListener 클래스 :
@SuppressLint("ShowToast")
공용 클래스 MyLocationListener는 LocationListener를 구현은 {
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
location.getLatitude();
location.getLongitude();
String strText ="My current location is: " + "Latitude = " + location.getLatitude() + " Longitude= " + location.getLongitude();
Toast.makeText(GpsModule.cont, strText, Toast.LENGTH_SHORT).show();
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
Toast.makeText(GpsModule.cont, "GPS disabled", Toast.LENGTH_SHORT).show();
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Toast.makeText(GpsModule.cont, "GPS enabled", Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
그 라인을 어디에서 부릅니까? –
이 처리기 또는 비동기 작업에서 호출되는 이유는 무엇입니까? –
끊임없이 전화하지 않는 것이 확실합니까? –