- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我试图在我的应用程序中正确使用 OpenGL,但在使用生命周期方法时遇到了一些问题:onPause()
和 onResume()
.
Activity Life-cycle
A GLSurfaceView must be notified when the activity is paused and resumed. GLSurfaceView clients are required to call onPause() when the activity pauses and onResume() when the activity resumes. These calls allow GLSurfaceView to pause and resume the rendering thread, and also allow GLSurfaceView to release and recreate the OpenGL display.
首先,我有点困惑,因为 onPause()
和 onResume()
在 Android 的其余部分中都是系统调用的生命周期事件(Activity/fragment )。这里,从描述(包括onPause()和onResume()中的详细描述)来看,他们似乎必须由开发者手动调用。
我一直在使用 GLSurfaceView
没有调用 onPause()
和 onResume()
并且没有注意到一个问题。但是,为了玩球(并减少恢复 Activity 时奇怪行为的可能嫌疑人),我正在尝试按照文档中的描述添加它们。
不过似乎使用 onResume() 会导致抛出 NullPointerException
:
07-23 13:20:08.570: E/AndroidRuntime(20777): Caused by: java.lang.NullPointerException
07-23 13:20:08.570: E/AndroidRuntime(20777): at android.opengl.GLSurfaceView.onResume(GLSurfaceView.java:544)
07-23 13:20:08.570: E/AndroidRuntime(20777): at com.ActivityNameHere.onResume(ActivityNameHere.java:151)
我是否缺少将 Activity
注册到 View
的步骤?
最佳答案
onPause()
和 onResume()
仍在破坏我的实现 - 但公平地说,它们不再发生崩溃:
The following GLSurfaceView methods can only be called after setRenderer is called:
getRenderMode()
onPause()
onResume()
queueEvent(Runnable)
requestRender()
setRenderMode(int)
在某些情况下,我没有在 Activity.onResume()
之前调用 setRenderer()
。
关于android - GLSurfaceView 生命周期方法 onPause() 和 onResume(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11612839/
假设我有 3 个 Fragment,BaseFragment,以及第一个 fragment 和第二个 fragment 。 我已经实现了 BaseFragment 的 onResume() 并编写了一
这是我的第一个应用程序,所以这个问题/答案可能非常基本。我目前有 onPause(); ,当玩家离开屏幕时停止播放音乐。我尝试做类似的事情,但使用 onResume,以便再次播放音乐(backgrou
如何重载onResume()以正确的方式工作?我想从 activity 返回到 MainActivity ,我希望在其中具有与应用程序启动后相同的状态。我想使用 recreate() 但它循环了或者类
出于某种原因,当我在代码中声明 onResume() 时,它会无缘无故地让我的程序崩溃,甚至无法打开。 这是我的 onResume() 代码: public void onResume() {
我遇到了一个棘手的问题。我有两个标签页主机 ...标签页主机 A 和标签页主机 B。每个选项卡主机都有三个选项卡(我们称它们为 A1、B1、A2、B2 等)。 选项卡主机 B 从 Activity A
我的应用程序有一个问题,如果我返回到一个 Activity ,我会收到一条错误消息,指出数据库已关闭: ERROR/AndroidRuntime(3566): Caused by: java.lang
在我的 android 应用程序中,我有一个问题已经 3 天无法解决了。我阅读了很多帖子和答案,但仍然找不到我的解决方案。 我的问题是当我按下主页按钮并在很长时间后返回应用程序时它崩溃了(NullPo
我如何实现一个无限滚动到 onResume(),目前是 onCreateView,我实现了一个无限滚动,它工作得很好,但是当涉及到 onResume() 时,它在另一个显示空白数据时不起作用。 这是o
我在我的 Android 应用程序中使用谷歌地图。一切都很好,但是当我没有启用 GPS 服务时,我会显示一条消息来启用。当我启用 GPS 并在我的 Fragment der map 中返回时,仅当我按
我一直在搜索这个,但不知道会发生什么...... 当我回到上一个 Activity 时,我的组件已正确初始化,但它们上面有一个新组件... 我的意思是,在 Debug模式下,我遵循并执行了 onRes
我读过一些与我的问题相似的帖子,最相似的问题在这里:Strange onPause(), onResume() behaviour in fragments 我正在使用 FragmentPagerAd
我已经阅读了关于 onResume() 和 onStart() 的文档,但我仍然不明白的一件事是 onResume() 在没有 onStart() 之前被调用? 最佳答案 请引用Android Act
我正在尝试制作一个简单的记事本应用程序,我想在“新建笔记” Activity 完成且主屏幕恢复时刷新笔记。但是,当我尝试使用此代码打开应用程序时,我会强制关闭。如果我删除 OnResume 东西,它不
这个问题在这里已经有了答案: Android: Under what circumstances would a Dialog appearing cause onPause() to be cal
我有一个问题。在为预览初始化相机并将另一个应用程序聚焦后,然后返回我的应用程序:预览显示为黑色。如果我继续拍照,它会拍摄我正常指向相机的位置的照片。 我在 OnResume() 覆盖上做错了什么吗?相
我正在使用列表适配器来显示不同的商店,当有人选择商店时,它会将他们带到一个新的 Activity 中,他们可以在该 Activity 中将商店添加到该屏幕上的收藏夹。 有一个调用 finish();
我有一个 Intent,它通过一个长的 Extra 从我的数据库中获取信息。它还通过 String Extra 设置 Activity 的标题。 现在,当我第一次启动 Activity 时,一切都完美
所以我有我的主要 Activity ,当您按下按钮时,它会启动 Activity 2。启动 activity2 后,我按下主页按钮,它将在 activity2 触发 onPause,然后 androi
我正在编写一个购物车应用,其中我允许用户选择要购买的商品并将他们需要的商品添加到购物车,为此我给出了两种不同的标签, 第一个标签,浏览产品 第二个标签,浏览购物车中的商品 [用户添加] 这里我遇到了一
我有问题。当我第一次启动我的 android 应用程序时,在主要 Activity 中 onCreate 和 onResume 都会被调用。但我只想被称为 onCreate。 我能做什么? 最佳答案
我是一名优秀的程序员,十分优秀!