简体   繁体   中英

Android Disable any onTouch

I have developed an Android App that communicates via HTTP-Request with a server. Some times it takes more time for a request so the app shows just a black screen and passes some seconds later. Sometimes the black screen appears some seconds later and you can send the request again and again.

Is there any possibility to disable the onTouch-Events or show a layer while the screen is loading?

Thank you.

use an asyncTask and launch your httprequest in the doInBackground() method, and for blocking the user , just display a ProgressDialog :

class YourRequestTask extends AsyncTask<Void, Void, JSONObject> {

        ProgressDialog progress;
        Context context;

        public YourRequestTask(Context context) {
             this.context = context;
        }

        @Override
        protected void onPreExecute() {
            progress = ProgressDialog.show(context, null,"Please wait...");
        }

        @Override
        protected JSONObject doInBackground(Void... params) {
            //do your work here for your http request
        }

        @Override
        protected void onPostExecute(JSONObject result) {
            progress.dismiss();
                        Log.i(TAG, "result is "+result.toString());
        }

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM