我正在做一个应用程序,该应用程序创建一个以太坊钱包并在您触摸按钮寄存器时发送一些以太坊,大约需要1分钟,而此时我想显示一条消息:创建一个钱包,请稍等。
当我显示消息时,它不会创建钱包,或者会创建钱包,但不会显示消息。
PS:如果有人知道如何节省时间,这将对我有很大帮助。
谢谢
答案 0 :(得分:0)
感谢您的帮助...和负面的帮助。
无论如何我都解决了,我将解决方案留在下面:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ActivityMain);
errorMsg = new AlertDialog.Builder(this);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new MyAsyncTasks().execute();
}
});
}
class MyAsyncTasks extends AsyncTask<Void, Void, String> {
// ProgressDialog dialog;
@Override
//It will show a message during your background
protected void onPreExecute() {
dialog = new ProgressDialog(mainActivity.this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setTitle("Add title");
dialog.setMessage("Add message");
dialog.setIndeterminate(true);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}
@Override
protected void onPostExecute() {
dialog.dismiss(); // Close the Dialog
//Show a window with error or operation succesfully
if(hash.equals("Error")){
displayError("Error", "Error");
dialog.cancel();
}
else{
displayConfirmation("Operation Succesfully");
dialog.cancel();
}
}
@Override
protected String doInBackground(Void... voids) {
dialog.show();
// your code to do you background activity
}
}