我想在两个活动之间添加进度条
在android应用程序中,当从第一个活动调用第二个活动时,我想在两个活动之间放置进度条,以便该应用程序看起来处于运行状态,并且我认为这样的事情是通过线程完成的,如果有人知道这一点,请帮助我..
提前致谢。
In android application when second activity is being called from first one i want to put progressbar between two activities, so that application seems that it is in running state, and i think such thing is done through thread,help me if anyone knows this..
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Kartik 是对的,但是让我添加更多内容以显示活动内的进度条。
当您想要显示进度条并在后台获取数据时,您应该在第二个活动中实现 AsyncTask。
下面是一个示例:
添加此 PerformBackgroundTask 类后,无论何时要执行,都需要调用
execute()
来执行相同的操作。Kartik is right, But let me add more to show Progressbar inside activity.
As you want to show Progressbar along with fetching data in background,you should implement AsyncTask in your second activity.
Here is an example:
After adding this performBackgroundTask class, you need to call
execute()
for the same whenever you want to execute.您必须使用 AsyncTask 或 Thread 来获取所选数据的详细信息。通过使用它,您可以解决在两个活动之间显示进度条的问题。
AsyncTask 基本示例: AsyncTask
You must use AsyncTask or Thread for getting the details of selected data. By using this you can solve your problem of displaying progressbar between two activities..
AsyncTask basic Example : AsyncTask
在android中只有主线程,也称为UI线程,可以进行UI操作。因此,您无法显示新线程的进度条。
我认为问题的解决方案可能会显示您的第二个活动(可能为空),显示 onCreate() 的进度对话框,然后在活动中执行任何繁重的工作。
希望这有帮助。
In android only the main thread, also called the UI thread, can to UI operations. So, you cannot show a progress bar from a new thread.
I think the solution to your problem may to show your second activity (possibly empty), show progress dialog from onCreate() then do any heavy lifting in the activity.
Hope this helps.
只需在进行计算的活动中创建 ProgressDialog 即可。
当你的任务完成后,关闭它,
但一定要从 UI 线程中显示和关闭对话框。 AsyncTask 可能是这种情况的最佳解决方案
Just make ProgressDialog in the activity that make your calculations.
and when your task is done close it
But be sure to show and dismiss dialog from UI thread. AsyncTask is probably the best sollution for such case