Android - 从另一个活动启动一个活动时可以强制调用 View.onSizeChanged
我有一个基本上只是闪屏的活动。此活动中的按钮启动一个新活动,其中有一个视图,该视图依赖于 View.onSizeChanged 回调来设置关键资源(它需要大小值来设置图块网格)。
我第一次运行该应用程序时,一切正常。 onSizeChanged
回调在创建视图后的某个时刻被调用,并且图块网格被正确设置。如果我然后点击后退按钮(这会让我返回到启动屏幕活动并清理/销毁其他活动),一切仍然没问题。从启动屏幕(无需完全退出应用程序),如果我再次单击开始按钮,当尝试设置第一个图块时,我会收到空指针异常(因为网格为空,因为 View .onSizeChanged 未调用)。
有没有一种方法,或者甚至是否适合,在每次启动第二个活动时强制保证调用 View.onSizeChanged
,从而创建需要它的视图?
如果不发布代码,这是否足够有意义?
I have an activity that is basically just a splash screen. A button in this activity starts a new activity which has a view in it that depends on the View.onSizeChanged
callback to setup critical resources, (it needs the size values to set up a grid of tiles).
The first time i run the app, everything works fine. The onSizeChanged
callback is called at some point after the view is created, and the tile grid gets set up correctly. If I then hit the back button, (which takes me back to the splash screen activity and cleans up/destroys the other activity), things are still ok. From the splash screen, (without exiting the app altogether), if I then click the start button again, I get a null pointer exception when the first tile is trying to be set, (because the grid is null, because View.onSizeChanged
was not called).
Is there a way to, or is it even appropriate to, force a guaranteed call to View.onSizeChanged
every time the second activity is started, and hence the view needing it is created?
Does this make enough sense without posting the code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论