使用来回按钮从一个活动导航到另一个活动时如何关闭进度对话框?
我的 Android 应用程序中有 4 个活动。第一个导致第二个,第二个到第三个等等。每个活动都从网络获取一些数据。这需要一些时间,所以我添加了一个进度对话框来让用户了解它。现在的问题是,当我按后退按钮时,进度对话框仍然存在。我应该在哪里编写miss()函数来关闭进度对话框?
PS:当我按两次后退按钮时它会消失。我应该在 onStart()、onResume() 上写解雇还是在哪里???
这是代码:
private void onFileClick(Option option) {
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setProgress(10);
progressDialog.setMax(100);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage("Loading Data...");
progressDialog.show();
Intent i;
i = new Intent(this, ChannelVideoListActivity.class);
startActivity(i);
progressDialog.dismiss();
}
I have 4 Activities in my android app. 1st leads to 2nd , 2nd to 3rd and so on.Each activity fetch some data from net.It takes some time in it so i have added a progress dialog box to let users know about it. Now the problem is that when i press the back button the progress dialog is still there. Where should i write the dismiss() function to dismiss that progress dialog box?
PS:It dismisses when i press back button twice. Should i write dismiss on onStart(), onResume() or where ???
Here is the code :
private void onFileClick(Option option) {
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setProgress(10);
progressDialog.setMax(100);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage("Loading Data...");
progressDialog.show();
Intent i;
i = new Intent(this, ChannelVideoListActivity.class);
startActivity(i);
progressDialog.dismiss();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试如下所示。
Try like the following.
//为此使用异步任务。
拨打此线路
//use Async Task for that.
call this line
我建议您以不同的方式编写
ChannelVideoListActivity
。您可能正在调用函数或编写代码来从网络加载数据,然后显示该数据或执行一些数据获取操作。
从
onCreate()
中删除所有内容,并将其放入AsyncTask
的doInBackGround()
函数中,并在 AsyncTask 的 onPreExecute 中调用进度对话框,并在 < code>onPostExecute() 关闭对话框。在 setContentView() 方法调用之后,从 ChannelVideoListActivity 的 onCreate() 调用此 AsyncTask 作为
new TaskClass().execute()
,然后简单地从之前的意图调用 ChannelVideoListActivity 。
I suggest You write your
ChannelVideoListActivity
differently.You might be calling function or writing code to load data from web and then show that or doing some data fetching operation.
Remove all from
onCreate()
and put it in anAsyncTask
'sdoInBackGround()
function and in AsyncTask's onPreExecute call your progress dialog and inonPostExecute()
dismiss dialog.Call this AsyncTask from onCreate() of ChannelVideoListActivity after setContentView() method call as
new TaskClass().execute()
and Simply call ChannelVideoListActivity from it's previous with intent.
您的呼叫流程存在问题并且进度条消失。
它应该是:
或者,如代码:
PS:在启动新活动之前不要启动进度栏活动。启动活动,然后启动进度栏。
there is a problem in your flow of calling and dismiss of progress bar.
It should be:
Or, as code:
PS: DONT start the progress bar before launching the new activity. Launch the activity and then start Progress bar.