我有一个使用GPS线的简单android应用程序的问题。吐司不会从屏幕上消失
我班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
}
}
你在哪里叫这些线? –
这是在处理程序或任何异步任务中调用? –
你确定它不是经常被调用吗? –