Which Activity Life cycle gets called when app redirect to settings

我只是一个虾纸丫 提交于 2019-12-25 06:03:17

问题


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.


回答1:


A good way to find out is using the build in caller methods triggered, when one event like on pause() is called, then you log the name of the event, and voila then you know which class is triggered to which time.




回答2:


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 :-)



来源:https://stackoverflow.com/questions/25616956/which-activity-life-cycle-gets-called-when-app-redirect-to-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!