“启动超时已过期,放弃唤醒锁定”的监听器或通知

时间:2012-07-20 14:20:53

标签: android android-activity

在我的一个测试设备中,我在LogCat中收到了这个可怕的警告:

07-20 09:57:02.093: W/ActivityManager(1159): Launch timeout has expired, giving up wake lock!
07-20 09:57:02.218: W/ActivityManager(1159): Activity idle timeout for HistoryRecord{4072b5e8 com.rero.myapp/.MyActivity}

我最初的研究表明,这是一个常见的眉毛提升者:

  1. “该应用可能有exceeded the VM budget并且内存不足。”
  2. “这can be ignored。”
  3. Network problem
  4. 活动是taking to long to start(在UI线程上处理过多?)
  5. 服务&广播涉及HTTP
  6. 依旧...
  7. 我的问题是:

    1. “启动超时已过期”的含义是什么?该系统做什么? (例如,一个消息来源声称它会导致我的申请被杀,但我实际上看到我的申请在被冻结1-2分钟后正常进行)
    2. 是否有在我的应用程序中通知有关此警告的方法?

1 个答案:

答案 0 :(得分:2)

以下是我尝试的一般想法,但是你如何处理AsyncTask取决于你获得状态后你正在做什么。我会做这样的事情:

private class GetHttpStatus extends AsyncTask<String, Void, Boolean> {
    @Override
    protected Boolean doInBackground(String[] params) {
        private boolean status;

        //this will be the string you pass in execute()
        String urlString = params[0];

        HttpURLConnection httpConnection;
        try {
            URL gurl = new URL(urlString);
            URLConnection connection = gurl.openConnection();
            connection.setConnectTimeout(5 * 1000);
            httpConnection = (HttpURLConnection) connection;
            int responseCode = httpConnection.getResponseCode();
            if(responseCode == HttpURLConnection.HTTP_OK) {
                status = true;
            }
        } catch (Exception e) {
            status = false;
        } finally { 
            if(httpConnection != null) httpConnection.disconnect();
        }
        return status;
    }

    @Override
    protected Void onPostExecute(Boolean result) {
        //Here you'll do whatever you need to do once the connection
        //status has been established
        MyActivity.notifyHttpStatus(result);
    }
}

//in your Activity somewhere, you would call...

new GetHttpStatus.execute("http://www.amazon.com");