【问题标题】:BrowserActivity has leaked windowBrowserActivity 已泄露窗口
【发布时间】:2013-05-27 10:58:40
【问题描述】:

我有一个使用 GCM 推送通知的应用。当我将通知推送到我正在测试的手机(HTC Desire C、三星迷你等)时,它工作正常。通知是修复了错误的应用的网址。

通常情况是收到推送,单击浏览器打开并开始下载。下载完成后,用户可以点击通知抽奖中的通知并安装/升级应用。

问题是当我尝试在 Motorola defy mini XT320 上运行它时。它可以接收推送,但浏览器在关闭之前打开大约一秒钟左右,并且没有开始下载。

有人知道为什么吗?以下是我如何生成通知以及错误。当浏览器打开时,我可以看到一个对话框弹出一瞬间。我知道该错误可能与此有关,因为它是泄漏的窗口错误。我没有创建此对话框,它是 Android 浏览器活动的一部分。

提前致谢。

 private static void generateNotification(Context context, String message) {
        int icon = R.drawable.ic_launcher;
        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);

        String title = context.getString(R.string.app_name);


        //Intent notificationIntent = new Intent(context, EntryActivity.class);
        Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(message));


        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent =
                PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        // Play default notification sound
        notification.defaults |= Notification.DEFAULT_SOUND;

        // Vibrate if vibrate is enabled
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notificationManager.notify(0, notification);     

    }

.

05-31 15:39:01.940: V/InputMethodManager(1310): focusOut: android.widget.EditText@408d6ca0 mServedView=android.widget.EditText@408d6ca0 winFocus=false
05-31 15:39:02.170: V/InputMethodManager(1310): focusOut: android.webkit.WebView@408bb1a0 mServedView=android.widget.EditText@408d6ca0 winFocus=false
05-31 15:39:02.180: V/browser(1310): BrowserActivity.onDestroy: this=com.android.browser.BrowserActivity@407ec730
05-31 15:39:02.290: E/WindowManager(1310): Activity com.android.browser.BrowserActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@408da548 that was originally added here
05-31 15:39:02.290: E/WindowManager(1310): android.view.WindowLeaked: Activity com.android.browser.BrowserActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@408da548 that was originally added here
05-31 15:39:02.290: E/WindowManager(1310):  at android.view.ViewRoot.<init>(ViewRoot.java:259)
05-31 15:39:02.290: E/WindowManager(1310):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
05-31 15:39:02.290: E/WindowManager(1310):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
05-31 15:39:02.290: E/WindowManager(1310):  at android.view.Window$LocalWindowManager.addView(Window.java:424)
05-31 15:39:02.290: E/WindowManager(1310):  at android.app.Dialog.show(Dialog.java:241)
05-31 15:39:02.290: E/WindowManager(1310):  at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
05-31 15:39:02.290: E/WindowManager(1310):  at com.android.browser.BrowserActivity.onDownloadStart(BrowserActivity.java:3492)
05-31 15:39:02.290: E/WindowManager(1310):  at com.android.browser.Tab$4.onDownloadStart(Tab.java:1349)
05-31 15:39:02.290: E/WindowManager(1310):  at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:388)
05-31 15:39:02.290: E/WindowManager(1310):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 15:39:02.290: E/WindowManager(1310):  at android.os.Looper.loop(Looper.java:130)
05-31 15:39:02.290: E/WindowManager(1310):  at android.app.ActivityThread.main(ActivityThread.java:3689)
05-31 15:39:02.290: E/WindowManager(1310):  at java.lang.reflect.Method.invokeNative(Native Method)
05-31 15:39:02.290: E/WindowManager(1310):  at java.lang.reflect.Method.invoke(Method.java:507)
05-31 15:39:02.290: E/WindowManager(1310):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
05-31 15:39:02.290: E/WindowManager(1310):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
05-31 15:39:02.290: E/WindowManager(1310):  at dalvik.system.NativeStart.main(Native Method)

[编辑1]

 @Override
    protected void onMessage(Context context, Intent intent) {
        Log.i(TAG, "Received message");
        String message = intent.getExtras().getString("price");

        Log.e(TAG, "message from gcm = " + message);


        Uri Download_Uri = Uri.parse(message);

        DownloadManager.Request r = new DownloadManager.Request(Download_Uri);

     // This put the download in the same Download dir the browser uses
     r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "RR3UPGRADE");



     // Notify user when download is completed
     // (Seems to be available since Honeycomb only)
    // r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

     // Start download
     DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
     dm.enqueue(r);

        displayMessage(context, message);
        // notifies user
        generateNotification(context, message);
    }

.

06-04 11:38:05.624: I/ActivityManager(207): Starting: Intent { act=android.intent.action.VIEW dat=content://downloads/all_downloads/63 typ=application/vnd.android.package-archive flg=0x10000001 cmp=com.android.packageinstaller/.PackageInstallerActivity } from pid 421
06-04 11:38:05.664: W/PackageParser(1203): Skipping dir: /all_downloads/63
06-04 11:38:05.664: W/PackageInstaller(1203): Parse error when parsing manifest. Discontinuing installation

【问题讨论】:

  • 好的。我追溯了 logcat 错误,看起来下载有问题。 W/PackageParser(1203): Skipping dir: /all_downloads/63 if (!sourceFile.isFile()) { Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath); mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK; return null; }。好像下载不成功。
  • 你有什么想法可以解决这个问题吗?
  • 我尝试将 downloadManager 代码与 AsyncTask 一起放置,因为我发现一个线程表明要下载 .apk,最好异步执行。没什么区别。
  • 对不起,我想我从这一点上一无所知。
  • 好的,感谢您到目前为止的帮助

标签: android android-intent dialog push-notification


【解决方案1】:

对于摩托罗拉 Defy Mini XT320 中的浏览器问题不是一个确切的解决方案(这实际上可能是正常操作,因为摩托罗拉可能已经决定在浏览器中设置限制以下载可疑文件,并且见鬼的文件.apk 扩展名可能非常危险),但您实际上可以直接请求DownloadManager 下载您的文件。

示例代码请参见https://stackoverflow.com/a/9033224/1893766

【讨论】:

  • 嗨,我已经使用了你建议的代码。我已经放置在 GcmIntentService onMessage 方法中。当我发出推送通知时,我将新应用的 URL 推送到手机上。您的代码确实下载了新文件并存储在下载文件夹中,但在安装时由于清单而出现包错误。它在我的 HTC oneX 上运行良好,但在 Motorola defy xt320 上无法安装。摩托罗拉正在运行 2.3.6。如果我将浏览器指向服务器上的 apk 文件,它将下载该应用程序,但不会从下载文件夹安装。你有什么想法为什么?谢谢
  • 您应用的最低 SDK 版本是多少?您可以在 XT320 上手动安装 apk (adb install &lt;your_app.apk) 吗?下载到设备上的包怎么样,可以手动安装吗?
  • 您好,清单中的最小 sdk 设置为“8”。如果我将浏览器指向服务器上的 apk 文件,应用程序安装正常。安装应用程序后,我会创建一个推送通知,其中包含指向 apk 的 URL(完全相同)。我收到推送,它会下载并存储在下载文件夹中。当我单击下载文件夹中的链接时,我收到上述软件包安装错误。
  • 我注意到的一件事。当我首先从浏览器安装应用程序时,它在下载列表中的 apk 名称下具有 url。当我从 push/downloadManager 下载应用程序时,下载列表中仅显示 apk 的名称。
  • 嗯... 1. 您应该无法通过 PackageInstaller 安装完全相同的 .apk 两次(这是正常的)。 2.希望服务器上的.apk没有损坏?
【解决方案2】:

我找到了下载管理器无法正常工作的原因,但仍不确定。

// Start download
     DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
     dm.enqueue(r);

        displayMessage(context, message);
        // notifies user
        generateNotification(context, message);

.

在上面的代码中,当我启动下载管理器时,对 displayMessage() 和 generateNotification() 的后续调用似乎会干扰下载。当我注释掉后续代码时,DownloadManager 似乎工作正常。就像我说不知道为什么。

【讨论】:

  • 当时你有没有尝试更改订单(以便下载管理器的请求最后出现)?
猜你喜欢
  • 1970-01-01
  • 2014-03-16
  • 2016-06-26
  • 2020-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多