本文介绍了如何显示ProgressDialog时preparing展现另一个活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要证明与MapView类的活动,如果用户在列表项长点击。
这个过程需要一段时间,所以我想显示用户progressdialog,而应用程序挂起。
这里是code:

I need to show activity with MapView, if user long clicked on the list item.This process takes a while, so I would like to show user progressdialog, while application hangs.Here is the code:

ListView listView = (ListView) findViewById(android.R.id.list);
listView.setOnItemLongClickListener (new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView parent, View view, int position, long id) {
...
  ProgressDialog dialog = ProgressDialog.show(getApplicationContext(), "", "Loading. Please wait...", true);
  Intent intent = new Intent(getBaseContext(), Map.class);
  startActivity(intent);

我已选择正确的方法?获得不同的FC现在(取决于选择用于ProgressDialog的上下文中)。在我的情况可以显示进度条来?

Have I chosen correct approach? Getting different FCs now (depending on the context chosen for ProgressDialog). Can ProgressBar be shown in my scenario?

UPD 。我试着开始活动之前,显示吐司。同样,面包只显示在已经显示地图。不明白发生了什么。如果我删除startActivity code,那么吐司立即显示。

Upd. I've tried to show Toast before starting activity. Again, Toast is shown only when Map is already displayed. Don't understand what happens. If I remove startActivity code, then Toast is displayed immediately.

推荐答案

您做lenghty preparation自己在图形页面的onCreate()?你不应该,因为它会阻止UI线程....

Are you doing the lenghty preparation itself in MapView's onCreate() ? You should not because it will block the UI thread....

相反,你应该做的 - 地图活动的onCreate内(),你应该产生一个新的AsyncTask(理想),并显示进度条出现(并显示进度条后立即退出的onCreate())。然后在它完成后的AsyncTask(以postExecuted()),你应该驳回进度对话框并显示地图。 PostExecuted()在UI线程中运行,因此您可以安全关闭该进度条。

Instead what you should do - inside of the Map activity's onCreate(), you should spawn a new AsyncTask (ideally) and show progress bar there (and exit the onCreate() right after showing progress bar). Then in the AsyncTask after it finishes (in postExecuted()) you should dismiss the progress dialog and show your map. PostExecuted() is run in UI thread so you can safely dismiss the progress bar.

你有FC和可能ANR数(不响应)都可能来,因为你在做某些事情/出UI线程。你应该建立/ UI线程解散你的UI组件,你SHOUDL不要在UI线程中运行lenghty操作。这是经验法则。

FCs you have and possibly ANRs (Not responding) are all probably coming because you do certain things in/out of the UI thread. You SHOULD create/dismiss your UI components in UI thread, and you SHOUDL NOT run lenghty operation in the UI thread. That's the rule of thumb.

这篇关于如何显示ProgressDialog时preparing展现另一个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 06:24