Android - 获得信号强度使我的应用程序无法响应

时间:2014-09-11 11:02:35

标签: android performance android-ui android-anr-dialog

我有一个通过GPRS连接的Android应用。在我的一项活动中,我正在使用PhoneStateListener检查GSM信号强度。取决于我更新图像的强度(强信号,弱信号......)

这是我正在使用的听众:

     private class MyPhoneStateListener extends PhoneStateListener
{
    /* Get the Signal strength from the provider, each tiome there is an update */
    @Override
    public void onSignalStrengthsChanged(SignalStrength signalStrength)
    {
        super.onSignalStrengthsChanged(signalStrength);

        Log.v("final","signal strength: "+signalStrength.getGsmSignalStrength());

        if (signalStrength.getGsmSignalStrength() < 5  ||  signalStrength.getGsmSignalStrength() == 99)
        {
            //poor connection or no connection

            signal.setImageResource(R.drawable.signal_poor);

        }
        else if(signalStrength.getGsmSignalStrength() >= 5 && signalStrength.getGsmSignalStrength() < 8)
        {
            signal.setImageResource(R.drawable.signal_very_poor);
        }
        else if(signalStrength.getGsmSignalStrength() >= 8 && signalStrength.getGsmSignalStrength() < 12)
        {
            signal.setImageResource(R.drawable.signal_medium);
        }

        else if(signalStrength.getGsmSignalStrength() >= 12)
        {
            signal.setImageResource(R.drawable.signal);

        }



    }

};

并且在onCreate()方法中我正在启动监听器:

          MyListener   = new MyPhoneStateListener();
    Tel = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

    Tel.listen(MyListener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

问题是,有时在访问活动时,我在(我的包裹)中收到ANR,原因:keyDispatchingTimedOut

      09-11 12:04:02.125    1270-1309/system_process E/ActivityManager﹕ ANR in com.example.myApp (com.example.myApp/.myActivity)
Reason: keyDispatchingTimedOut
Load: 1.84 / 1.26 / 0.53
CPU usage from 9732ms to 3045ms ago:
76% 1916/gsm0710muxd_bp: 12% user + 64% kernel / faults: 1 minor
10% 1875/com.example.universalapp: 8.1% user + 2.8% kernel / faults: 1488 minor 4 major
6.3% 1270/system_server: 5.4% user + 0.9% kernel / faults: 481 minor 2 majo

这些功能占用了76%的CPU?他们那么重吗?如何在不影响UI的情况下运行它们,并在信号强度发生变化时仍然更新UI?

0 个答案:

没有答案