应用程序重定向到设置时调用哪个活动生命周期 [英] Which Activity Life cycle gets called when app redirect to settings

查看:119
本文介绍了应用程序重定向到设置时调用哪个活动生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,如果未启用gps,我将调用gps设置菜单。我在Oncreate()方法中调用了这个。但是,我也想检查用户是否真的启用它?

我的问题是当用户从设置菜单返回时调用哪个活动生命周期方法。

我试图为OnResume方法编写代码。但即使启用了GPS,alertdilogue仍会弹出。

  if(gps.canGetLocation()){

latitude = gps.getLatitude();
longitude = gps.getLongitude();
altitude = gps.getAltitude();
gpsLocation =纬度:+纬度+,经度:+经度
+,海拔高度:+高度;
System.out.println(GPS @ Avaialable Form+ gpsLocation);

Logger.e(this,GPS Location,gpsLocation);
} else {
gps.showSettingsAlert();
}

我在OnCreate()和

  protected void onResume(){
// TODO自动生成的方法存根
super.onResume();
System.out.println(On Resume gets Called);


if(gps.canGetLocation()){

latitude = gps.getLatitude();
longitude = gps.getLongitude();
altitude = gps.getAltitude();
gpsLocation =纬度:+纬度+,经度:+经度
+,海拔高度:+高度;
System.out.println(GPS @ Avaialable Form+ gpsLocation);

Logger.e(this,GPS Location,gpsLocation);
} else {
gps.showSettingsAlert(); ()方法中的
}

解决方案

据我所知,唯一可靠的方法是通过侦听器(GpsStatus.Listener)设置并侦听gps更改 - 的LocationManager#addGpsStatusListener(...)。
在onGpsStatusChanged方法中,您可以对GpsStatus#GPS_EVENT_STARTED或GpsStatus#GPS_EVENT_STOPPED做出反应,并通过Handler更改UI的更新。希望这有助于: - )


In my application, I am calling gps setting menu if gps is not enabled. I called this in Oncreate() method. However, I also wants to check whether user actually enables it or not?

My Question is which activity life cycle method gets called when user get back from setting menu.

I tried to write code for OnResume method. But alertdilogue keeps poping even GPS is enabled.

    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();
    }

I called this code in OnCreate() and

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();
    }

in OnResume() Method.

解决方案

As far as I know the only reliable way is setup and listen to the gps changes via listener (GpsStatus.Listener) - LocationManager#addGpsStatusListener(...). In the onGpsStatusChanged method you can react to GpsStatus#GPS_EVENT_STARTED or GpsStatus#GPS_EVENT_STOPPED and change the update of your UI via Handler. Hope this helps :-)

这篇关于应用程序重定向到设置时调用哪个活动生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆