我有一个进度对话框,我在程序中使用了一个部分,我在后台进行了时间密集型操作,但是当对话框显示时,UI或微调器图标冻结/慢/犹豫使程序看起来好像冻结了一样.在我onPostExecute的我AsyncTask解雇对话.
为什么会发生这种情况,因为我在后台完成所有工作?
这是我的代码
pDialog = ProgressDialog.show(FullGame.this,"Starting New Game","Please Wait...", true);
new StartNewGame().execute();
private class StartNewGame extends AsyncTask<Void,Void,Boolean>{
@Override
protected Boolean doInBackground(Void... params) {
try{
ContentValues values = new ContentValues();
Cursor c = getContentResolver().query(Games.PART1_URI,new String[] {Games.PART1_NUM},
Games.PART1_GAME_ID+"="+gameID+" AND "+Games.PART1_FRAME_NUM+"="+10,null,null);
c.moveToFirst();
String num = c.getString(0);
int part1 =0;
if(num.equals("-")){
part1=0;
}else{
part1=Integer.parseInt(num);
}
c = getContentResolver().query(Games.PART2_URI,new String[] {Games.PART2_NUM},
Games.PART2_GAME_ID+"="+gameID+" AND "+Games.PART2_FRAME_NUM+"="+10,null,null);
c.moveToFirst();
int part2 = 0;
if(num.equals("-")){
part2=0;
}else{
part2=Integer.parseInt(num);
}
c = getContentResolver().query(Games.PART3_URI,new String[] {Games.PART3_NUM},
Games.PART3_GAME_ID+"="+gameID,null,null);
c.moveToFirst(); …Run Code Online (Sandbox Code Playgroud) 看到那个双窗口?我不知道为什么会发生这种情况.
码
像这样初始化进度对话框:
progressDialog = new ProgressDialog(context);
progressDialog.setMessage(messsage);
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
Run Code Online (Sandbox Code Playgroud)在值和值中定义了这样的样式-21:
<style name="AlertDialog.Theme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:textColorPrimary">@color/black</item>
<item name="android:background">@color/white</item>
<item name="android:textColor">@color/black</item>
<item name="colorAccent">@color/orange</item>
<item name="colorPrimary">@color/orange</item>
<item name="colorPrimaryDark">@color/darkerorance</item>
</style>Run Code Online (Sandbox Code Playgroud)
<item name="android:dialogTheme">@style/AlertDialog.Theme</item>
<item name="dialogTheme">@style/AlertDialog.Theme</item>
<item name="android:alertDialogTheme">@style/AlertDialog.Theme</item>
<item name="alertDialogTheme">@style/AlertDialog.Theme</item>Run Code Online (Sandbox Code Playgroud)
主题延伸自Theme.AppCompat.Light.NoActionBar.
这在Lollipop及以上版本上效果很好,但在棒棒糖前的图像中看起来很像.任何人都可以帮忙,告诉我我做错了什么?
我正在使用公共AsynTask下载数据,我正在尝试显示一个进度条,显示下载进度.我想我的代码是正确的,但我得到的只是一个spinner progressdialog.我错过了什么吗?为什么进度条不显示?这是代码.谢谢你的任何指示.
public class FileDownloader extends AsyncTask<String, Integer, Void>
{
private Context _appContext;
private HttpURLConnection _urlConn;
private ProgressDialog _progressDia = null;
private DialogInterface.OnCancelListener _progDiaCancelListener = new DialogInterface.OnCancelListener()
{
/**
* When the progress dialog is canceled, stop the GET request.
*/
public void onCancel(DialogInterface dialog)
{
FileDownloader.this.cancel(true);
}
};
/**
* Constructor.
* @param appContext
*/
public FileDownloader(Context appContext)
{
_appContext = appContext;
_progressDia = new ProgressDialog(_appContext, ProgressDialog.STYLE_HORIZONTAL);
_progressDia.setMax(100);
_progressDia.setTitle(_appContext.getString(R.string.diaHeader1));
_progressDia.setMessage(_appContext.getString(R.string.diaBody1));
_progressDia.setCancelable(true);
_progressDia.setIndeterminate(false);
_progressDia.setOnCancelListener(_progDiaCancelListener);
}
// Runs on the UI …Run Code Online (Sandbox Code Playgroud) Android的ProgressDialog允许您将当前进度和最大值设置为整数.这些值在对话框中显示如下:
一万〇二十三分之三千四百〇一
第一个数字是当前进度,第二个数字是最大值.
我还想展示测量单位.像这样的东西:
3401/10023 KB
这可能使用ProgressDialog吗?如果没有,您建议您将此信息提供给用户?我试图避免重新实现ProgressDialog以包含该单元.
我有一种情况,我正在加载一堆图像.在此过程中,我试图显示进度对话框,直到图像完全加载.我overrided的onBackPressed()方法,这样,当用户按下后退按钮时,活动将结束.
但是,如果在显示进度对话框时按下后退按钮,则不会调用后退键事件.所以我试着提供progressDialog.setCancelable(true).所以这现在允许我解除进度对话框,但我的后退键事件仍未被调用,因此我的活动在后台加载图像.
那么progressDialog当用户按下后退键时,如何同时停止和活动.
我已按照以下链接自定义进度对话框:
如何轻松地在ProgressDialog中居中进度指示器(当没有标题/文本传递时)
我想创建自定义进度对话框,就像在此图像中一样
但是该代码在我的应用程序中没有显示进度对话框.请指导我如何操作?还指导我如何根据我的项目主题更改进度对话框的颜色?
请检查以下示例代码.显示Toast消息但从不隐藏progressdialog.为什么?
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;
public class LoadExamActivity extends Activity implements Runnable{
ProgressDialog pd;
Handler Finished = new Handler(){
@Override
public void handleMessage(Message msg){
Toast.makeText(getApplicationContext(), "DONE!", Toast.LENGTH_SHORT).show();
pd.dismiss();
}
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.exam);
Toast.makeText(this, "START!", Toast.LENGTH_SHORT).show();
pd = new ProgressDialog(this);
pd.show(this, "Waiting...", "Please wait five seconds...");
Thread th = new Thread(this);
th.start();
}
public void run() {
//To change body of implemented methods use File | Settings | …Run Code Online (Sandbox Code Playgroud) 我有一个异步任务,它不会在完成任务时添加百分比.它始终保持在0%0/100
这是我的代码
private class getAppInfo extends AsyncTask<String, String, String> {
/** The system calls this to perform work in a worker thread and
* delivers it the parameters given to AsyncTask.execute() */
ProgressDialog dialog;
@Override
protected void onPreExecute() {
if(showLoading == true){
dialog = new ProgressDialog(SelfHelp.this);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMessage("Loading");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.setMax(100);
dialog.setProgress(100);
dialog.show();
}
}
@Override
protected String doInBackground(String... urls) {
String xml = null;
int count = 0;
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet …Run Code Online (Sandbox Code Playgroud) 目标:让ProgressDialog显示"正在加载...",直到下一个活动完全加载并显示在屏幕上.
尝试将ProgressDialog上下文和活动设置为原始活动.还尝试使用getApplicationContext()和getParentContext().最后两种方法的例外情况.需要这样做因为目标活动由于非简单的布局文件而呈现缓慢.(由于组织问题,现在无法解决这个问题.)结果目标活动需要1-2秒才能进入OnCreate,然后屏幕会变黑并持续5秒以上,然后进行绘制.渲染速度很慢.使用Hierarchy Viewer进行了审核,看到了很多红球,但现在无法修复.
阅读一些相关但尚未找到解决方法.例如,获取Context的各种方法之间有什么区别?
例如,这两次崩溃.使用源"活动"的"this"也不起作用.
// Context parentContext = this.getParent().getBaseContext();
Context parentContext = this.getApplicationContext();
ProgressDialogMenuable theProgressDialog = new ProgressDialogMenuable(parentContext,this);
theProgressDialog.setTitle("yeeha");
theProgressDialog.setMessage("weewah");
theProgressDialog.setIndeterminate(true);
theProgressDialog.setCancelable(true);
theProgressDialog.show();
Run Code Online (Sandbox Code Playgroud)
另外,奇怪的是,当我这样做时没有任何反应:theProgressDialog.show(); ActivityHelper.changeActivity(this,v,InsMyHoldingsActivity.class,extraMap,-1,-1); 用户单击按钮以显示下一个活动,但ProgressDialog与活动启动冲突,除按钮变为黄色触控外,实际上没有任何其他操作.下面的按钮有效.删除ProgressDialog创建,它的工作原理.没有记录控制台消息.肯定会对开发人员有点遗憾.
我想用android中的RxJava替换我的AsyncTask.我目前的AsyncTask是这样的:
public class ProgressBarAsyncTask extends AsyncTask<Void,Void,Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
ringProgressDialog = ProgressDialog.show(context,"MyProgressBarTitle","Working please wait",true, false);
}
@Override
protected Void doInBackground(Void... void) {
//do work
myTask();
return null;
}
@Override
protected void onPostExecute(Void void) {
super.onPostExecute();
ringProgressDialog.dismiss();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的RxJava替代品:
public static Observable<Void> getObservable(final Context context,final String... params) {
return Observable.defer(new Func0<Observable<Void>>() {
@Override
public Observable<Void> call() {
return Observable.just(myTask());
}
});
}
public static Subscriber<Void> getSubscriber() {
Subscriber<Void> subscriber = new Subscriber<Void>() {
@Override
public void …Run Code Online (Sandbox Code Playgroud)