【发布时间】:2023-12-18 19:16:02
【问题描述】:
在我的应用程序中,如果未启用 gps,我将调用 gps 设置菜单。我在 Oncreate() 方法中调用了它。但是,我还想检查用户是否真的启用了它?
我的问题是当用户从设置菜单返回时调用哪个活动生命周期方法。
我尝试为 OnResume 方法编写代码。但是即使启用了 GPS,alertdilogue 也会不断弹出。
if (gps.canGetLocation()) {
latitude = gps.getLatitude();
longitude = gps.getLongitude();
altitude = gps.getAltitude();
gpsLocation = "Latitude: " + latitude + ", Longitude:" + longitude
+ ",Altitude:" + altitude;
System.out.println("GPS @ Avaialable Form"+gpsLocation);
Logger.e(this, "GPS Location", gpsLocation);
} else {
gps.showSettingsAlert();
}
我在 OnCreate() 和
中调用了这段代码protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
System.out.println("On Resume gets Called");
if (gps.canGetLocation()) {
latitude = gps.getLatitude();
longitude = gps.getLongitude();
altitude = gps.getAltitude();
gpsLocation = "Latitude: " + latitude + ", Longitude:" + longitude
+ ",Altitude:" + altitude;
System.out.println("GPS @ Avaialable Form"+gpsLocation);
Logger.e(this, "GPS Location", gpsLocation);
} else {
gps.showSettingsAlert();
}
在 OnResume() 方法中。
【问题讨论】:
-
在应用导航到设置时调用 onstyop,如果您使用 startactivityfor resule 而不是 onactivity 结果调用,则在返回 onresume 时调用
标签: android android-activity gps lifecycle