android - "Launch timeout has expired, giving up wake lock"上的监听器或通知

标签 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. Activity 是 taking to long to start (在 UI 线程上处理太多?)
  5. 涉及 HTTP 的服务和广播.
  6. 继续 ...

我的问题是:

  1. “启动超时已过期”的含义是什么?系统有什么作用? (例如,一个消息来源声称它终止了我的应用程序,但实际上我看到我的应用程序在 1-2 分钟的感知卡住后正常进行)
  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");

关于android - "Launch timeout has expired, giving up wake lock"上的监听器或通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11581256/

相关文章:

android - 从 Android 应用程序共享文本时如何修复错误消息 "Please use a valid Web address"?

android - 查找Android中是否存在Activity的方法

java - 如何扩展 ListActivity where AppCompatActivity in Android Activity

java - (Android) 尝试抛出 OutOfMemoryError 时抛出 OutOfMemoryError

android - Jetpack 在深色模式下撰写 TextField 文本颜色

javascript - 无法在 inAppBrowser 内的 phonegap 中捕获 "document.(...).tagName"

java - 何时/不使用同步适配器

java - 不同对象的通用 Activity

Android:将附加功能更改为 Intent

android - 在android eclipse中调用多个 Activity