ImageView的导致崩溃,但只有从待机模式恢复时, [英] ImageView causes crash but only when resuming from standby mode

查看:230
本文介绍了ImageView的导致崩溃,但只有从待机模式恢复时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用其他两个类的活动类;他们中的一个延伸的ImageView和一个延伸BaseAdapter像这样:

I got an Activity class that uses two other classes; one of them extending ImageView and one that extends BaseAdapter like so:

我的ImageView类做一些进展,当它被调用,当我开始它的第一次就做什么,我想它。这也是这种情况,如果我preSS主页按钮,然后继续。
但由于某些原因,如果我从待机模式恢复这是行不通的。 (pressing,使屏暗手机上的按钮),当我解开手机崩溃。它崩溃的一个NullPointerException异常,并且从什么,当我尝试由BaseAdapter定义的GridView调用getChildAt()我可以读。

My ImageView class does some progresses when it is called and when I am starting it for the first time it does what I want it to. This is also the case if I press home button and then resumes. But for some reason it does not work if I resume from standby mode. (pressing the button on the phone that makes the screen dark) When I unlock the phone it crashes. It crashes on a nullPointerException, and from what I can read when I try to call getChildAt() on a GridView defined by the BaseAdapter.

这是任何方式让应用程序做同样的,当我preSS home键,当我设置手机在待机状态下?
编辑:

Is it any way to make the app do the same as when I press the home button, as when I set the phone in standby mode?

public MyCustomDefinedImageViewClass (Context context) {
super (context);
mContext = context;
    MyCustomDefinedImageViewClass someThing =(MyCustomDefinedImageViewClass)gridViewIGetTheChildFrom.getChildAt(some int);

}
这是什么原因造成我崩溃:

} This is what is causing my crash:

 11-19 22:00:48.200: E/AndroidRuntime(6252):     at my.package.name.MyCustomDefinedImageViewClass.<init>(MyCustomDefinedImageViewClass.java:57)

我不认为code正在帮助很多,这就是为什么我没有在第一时间发布了。

I do not think the code is helping to much and that was why I did not post it in the first place.

推荐答案

尝试添加

android:configChanges="keyboardHidden|orientation|screenLayout"

你的清单文件。崩溃是重启活动的结果时,锁屏出现。锁屏势力纵向,如果你还没有准备好处理它,然后你的应用程序可能会崩溃。

to your manifest file. The crash is a result of activity restart when the lock screen comes up. The lock screen forces portrait orientation and if you are not ready to handle it then your app may crash.

如果不做到这一点,尝试覆盖<一个href=\"http://developer.android.com/reference/android/app/Activity.html#onRetainNonConfigurationInstance%28%29\"相对=nofollow> onRetainNonConfigurationInstance()。

If that doesn't do it, try overriding onRetainNonConfigurationInstance().

请参阅这篇文章,了解如何留住对象信息:<一href=\"http://stackoverflow.com/questions/7783673/how-to-save-lot-of-object-in-onretainnonconfigurationinstance-in-android\">How保存在onRetainNonConfigurationInstance()很多物体的机器人

See this post for info on how to retain objects: How to save lot of object in onRetainNonConfigurationInstance() in android

也阅读了本 Android的线程组理解,当设备进入睡眠状态时会发生什么。

Also read this android-group thread for understanding what happens when device goes to sleep.

这篇关于ImageView的导致崩溃,但只有从待机模式恢复时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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