我尝试在回收器视图中更改设备的方向,但是当进度对话框出现时它总是崩溃。
如何解决这个问题?
这是我的代码:
私有类LoadOrdersListAgent扩展了AsyncTask {
@Override
protected void onPreExecute() {
dialog = new ProgressDialog(OrdersActivity.this);
ordersList = new ArrayList<>();
rvor = findViewById(R.id.recycler_view_orders_agent);
emptytv = findViewById(R.id.empty_view_orders_agent);
emptytv.setVisibility(View.GONE);
rvor.setHasFixedSize(true);
rvor.setLayoutManager(new LinearLayoutManager(OrdersActivity.this));
rvor.setItemAnimator(new DefaultItemAnimator());
dialog.setMessage("Loading....");
dialog.show();
}
@Override
protected void onPostExecute(Void aVoid) {
final OrdersAdapter adapter = new OrdersAdapter(getApplicationContext(), ordersList);
rvor.setAdapter(adapter);
rvor.setLayoutManager(new LinearLayoutManager(OrdersActivity.this));
srl.setRefreshing(false);
if (dialog.isShowing()) {
dialog.dismiss();
}
if (ordersList.isEmpty()) {
Log.d("TESTING.....", "LIST OF ORDERS ----->" + ordersList);
rvor.setVisibility(View.GONE);
srl.setVisibility(View.GONE);
emptytv.setVisibility(View.VISIBLE);
} else {
rvor.setVisibility(View.VISIBLE);
srl.setVisibility(View.VISIBLE);
emptytv.setVisibility(View.GONE);
}
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected Void doInBackground(Void... voids) {
ordersList = OrdersApi.getOrders(url, key);
return null;
}
}
private void swipeOrderLayout() {
srl = findViewById(R.id.swipe);
srl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if (new CheckNetworkUtil(OrdersActivity.this).isNetworkAvailable()) {
new LoadOrdersListAgent().execute();
// new LoadOrdersListAdmin()。execute(); 其他 Toast.makeText(OrdersActivity.this,“No Internet Connection!”,Toast.LENGTH_SHORT).show(); srl.setRefreshing(假); } }); }
答案 0 :(得分:1)
我在完成/销毁活动时没有取消进度对话时出现此错误。
解决方案使用dialog.dismiss();
在销毁或暂停活动之前解除进度对话
在你的情况下删除if条件,只需在postExecute方法
中调用dialog.dismiss();
答案 1 :(得分:0)
使用以下方式在Global中声明您的ProgressDialog:
在onCreate()上面添加以下代码:
private ProgressDialog dialog;
在onCreate()中添加此代码:
dialog = new ProgressDialog(OrdersActivity.this);
dialog.setMessage("Loading....");
dialog.show();
在onPreExecute方法中添加此代码,
if (!dialog.isShowing()) {
dialog.show();
}