Hossein Shahdoost
Hossein Shahdoost

Reputation: 1742

What is the easiest way to make input delay

I'm a new android developer,

Due to security reasons, I want to make input delay in my sign in action, (Just showing a ProgressDialog for like 2 seconds and then continuing the main procedure). I already know how I can do it using MultiThread programming, but since there is nothing going on in the other thread, I thought maybe there can be some way to do it without using background workers.

I would be glad if you could tell me an easy way to do it in android

Thanx

Upvotes: 1

Views: 231

Answers (3)

mavixce
mavixce

Reputation: 338

I suggest you to use Action Bar Sherlock you don't need threading. Just call

setSupportProgressBarIndeterminateVisibility(boolean)

i think learning this api harder than using threads but new generation Android (after api 11) apps generally use action bar progress.

Upvotes: 1

Hossein Shahdoost
Hossein Shahdoost

Reputation: 1742

Well, just for the future reference, I found another way to solve this problem using Timer, I think it's better than Background Thread, I created a wrapper function which calls the main event after an specific amount of time

public void onClick(View view) {
    try {
        progressDialog = ProgressDialog.show(this, "sometitle", "somecontent");

        /**
         * input delay
         */
        Timer delayWorker = new Timer();
        TimerTask task = new TimerTask() {
            public View view = null;

            @Override
            public void run() {
                onClickAction(view);
                this.cancel();
            }
        };

        task.getClass().getField("view").set(task, view);
        delayWorker.schedule(task, INPUT_DELAY);

    } catch (Exception e) {
        /**
         * error occurred
         */
    }

}


private void onClickAction(View view) {

      /**
       * actual action click
       */

 }

Upvotes: 0

Wagdi Kala
Wagdi Kala

Reputation: 53

You can delay the main thread for 2 sec.

Upvotes: 0

Related Questions