-1

我正在做一个应用程序,它创建一个以太坊钱包并在您触摸按钮注册时发送一些以太币,这大约需要 1 分钟,而它发生时我想显示一条消息说:创建一个钱包,请稍候。

当我显示消息时,它不会创建钱包,或者它会创建钱包但不会显示消息。

PS:如果有人知道如何减少时间来做到这一点,那将对我有很大帮助。

谢谢

4

1 回答 1

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
    }
}
于 2018-08-23T14:59:49.543 回答