几次重启后应用冻结 [英] App freezing after several restarts

查看:77
本文介绍了几次重启后应用冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个用于拍照的应用程序,将其显示以供接受,然后通过帖子将其上传到网络服务器.

I built this app that takes pictures, displays them for acceptance and uploads them to a webserver via post.

概念和执行非常简单.但是随后该应用程序在Android手机中冻结了(我有Xperia Z3 +,我拥有相当多的资源,也曾在Moto X中试用过.)

It is very simple in concept and execution. But then the app is freezing in the Android handset (I have an Xperia Z3+ which i has a fairly good amount of resources, also tried in a Moto X).

要尝试重现此图像,我需要拍张照片(它将自动尝试上传)...按下电源按钮以关闭屏幕...然后,当我点亮屏幕时,应用需要一段时间重新开始工作(可以看到,因为我有背景动画).重试这些内容后...该应用将冻结,我必须将其关闭以重试.

To try and reproduce this I take a picture (it will automatically tried the upload)... push the power button for the screen to shutdown... then when I light up the screen it takes a while for the app to start working again (I can see because I have a background animation). After some retries of these... the app will freeze and I'll have to close it to retry.

关于如何解决此问题的任何建议?

Any suggestions on how to troubleshoot this problem?

我的想法是,通过从屏幕上删除动画元素,我可以稍微缓解一下问题……至少在没有出现任何应用程序开关冻结的情况下,感知性能会好得多……因此,我希望能够使用活动生命周期事件中的onPause,onStop来清除动画.我猜这些对象已经序列化了,所以我将节省序列化和反序列化的时间,并且由于onResume,onRestart事件时不会看到任何冻结的应用程序,因此性能会有所改善.

My thinking is that I can aliviate the problem a little by removing the animation elements from the screen... at least the perceived performance will be far better is the app does not appear frozen on any app switch... therefore I want to be able to use the onPause, onStop from the activity lifecycle events to clear the animations. I guess those objects are serialized, so I will save serialization and deserialization time and also the perceived performance will improve as no freezed app will be seen while the onResume, onRestart events.

这可能吗?

非常感谢你卡盘

推荐答案

这不是由动画引起的,它可能是由于未捕获的异常或应用程序性能不佳引起的.

This isn't caused by the animation, it may be caused by an uncaught Exception or poor app performance.

要查看您的应用性能,请将需要反馈的所有长过程移至表单的 postShow()方法而不是 beforeShow的UI (AsyncTask)().如果不需要实时向UI反馈(IntentService),请考虑使用 Display.getInstance().scheduleBackgroundTask()在低优先级线程上运行任务在序列化它时,可以在 beforeShow()方法中完成.如果您的表单是手工编码的(不是GUI),请在 addShowListener()中进行繁重的长时间处理.

To review your app performance, move any long process that requires feedback to the UI (AsyncTask) to postShow() method of your forms and not beforeShow(). If it doesn't require feedback to UI in real time (IntentService), consider using Display.getInstance().scheduleBackgroundTask() which runs your task on a low priority thread while serializing it and this can be done in the beforeShow() method. If your forms are handcoded (Not GUI), do heavy long process in addShowListener().

还可以减少您在应用中使用的图像数量,因为这也可能会在加载沉重的图像时影响您的应用性能.

Also cut down the amount of images you use in your app as this could also hinder your app performance when loading heavy images.

避免不必要地使用 revalidate(),通常不会在循环中调用它,这有点贵,请改用 repaint().

Avoid unnecessary use of revalidate(), usually by not calling it in a loop, it's a bit expensive, use repaint() instead.

您还可以使用Android ddms来检查您的应用程序是否遇到一些错误.

You can also use Android ddms to check if your app is running into some errors.

锁定屏幕或将其最小化不会对您的应用造成任何影响,除了启动应用并显示启动屏幕时(如果在显示启动时将您的应用最小化,这通常会冻结该应用).我相信这是一个已知问题.

Locking your screen or minimizing shouldn't affect your app in anyway other than when the app is starting up and the splash screen is shown (This usually freezes the app if you minimize your app when splash is shown). I believe this is a known issue though.

另一个选择可能是挂起-恢复"行为.暂停应用程序(电源按钮,打来的电话等)后,将调用 stop()方法,并在返回时调用 start()方法.

Another option could be the "suspend-resume" behavior. When an app is suspended (power button, incoming phone call etc.) the stop() method is invoked followed by a call to the start() method when it returns.

如果在 stop()方法过程中有进度指示器,则restore调用将重新显示进度指示器,其前一表格为前表格".这样,当进度指示器消失时,它会显示以前的形式".您可以使用暂停/恢复"菜单在模拟器中测试此行为.

If you have a progress indicator during the stop() method then the restore call will reshow the progress indicator with the previous form as its "before form". That way when the progress indicator is dismissed it shows the "previous form". You can test this behavior in the simulator using the "suspend/resume" menu.

要解决此问题,只需将进度指示器放置在 stop()方法中,如下所示:

To workaround it just dispose the progress indicator in the stop() method as such:

public void stop() {
    current = Display.getInstance().getCurrent();
    if(current instanceof Dialog) {
        ((Dialog)current).dispose();
        current = Display.getInstance().getCurrent();
    }
}

这篇关于几次重启后应用冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆