如何在 Android 中生成加载屏幕?
问题是我来自另一个活动,当我尝试转到新活动时,它只是坐在旧活动上,直到显示新活动,所以我试图让它立即转到新活动,然后在获取内容时调出加载屏幕。 (内容来自网站或内部数据库)。
我已经尝试过 Android 开发网站上的 ProgressDialog,但它没有执行任何操作,因为 Activity 在显示任何内容之前就完成了加载,因此当它显示时,没有任何内容可以加载。
The problem is I am coming from another Activity, and when I try to go to the new Activity, it just sits on the old one until the new one is displayed, so I am trying to get it to go to the new Activity right away, and then bring up a loading screen while it gets the content. (The content is either coming from a website or an internal database).
I've tried the progressDialog from the Android development site but it doesn't do anything as the Activity finishes loading before showing anything, so by time it shows up, theres nothing to load.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先启动新活动,然后调用异步任务文件。当您关闭旧活动时,这将启动新活动。在新活动的 Oncreate 中调用异步任务类,如下所示
First start new activity first and then call the async task file.. this will start new activity when u close old one. in Oncreate of new activity call the asyn task class like below
作为建议,尝试减少第二个活动的 onCreate 方法中的代码。让它像调用 super 和设置内容视图一样简单。这将显示用 XML 设计的 UI。
将其余代码移至 onResume 方法。
下一步,如果您需要从数据库或外部获取一些数据,请尝试使用 线程(如何做到 & 这是什么)或 异步任务。
As a suggestion, try reducing the code in onCreate method of the second activity. Let it be as simple as calling super and setting the content views. This will bring up the UI as designed in XML.
Move rest of the code to your onResume method.
Next step, if you have some data to be fetched from DB or outside, try using the thread (how to do it & what is it) or async task.