Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9252107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:51:46+00:00 2026-06-18T10:51:46+00:00

i try this Tutorial i still confused how to add progress dialog in button

  • 0

i try this Tutorial

i still confused how to add progress dialog in button logout with asynctask

here is my activity.

package hariff.ltis.mainmenu;

import hariff.ltis.inputhama.CInputHamaApp;
import hariff.ltis.library.DatabaseHandler;
import hariff.ltis.library.UserFunctions;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import hariff.ltis.mainmenu.R;

public class MainMenu extends Activity{
    UserFunctions userFunctions;
    Button btnLogout;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        userFunctions = new UserFunctions();
        if(userFunctions.isUserLoggedIn(getApplicationContext())){
        setContentView(R.layout.main);
        btnLogout = (Button) findViewById(R.id.btnLogout);
        btnLogout.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                userFunctions.logoutUser(getApplicationContext());
                Intent login = new Intent(getApplicationContext(), LoginActivity.class);
                login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                startActivity(login);
                // Closing dashboard screen
                finish();
            }


        });


        loadUser();

        View button3Click = findViewById(R.id.button3);
        button3Click.setOnClickListener(new View.OnClickListener(){
             public void onClick(View v) {
                 // Perform action on click
                DataHama();
             }
        });

        }else{
            // user is not logged in show login screen
            Intent login = new Intent(getApplicationContext(), LoginActivity.class);
            login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(login);
            // Closing dashboard screen
            finish();
        }





    }
    /*private void InputData(){
        Intent i = new Intent(this, SaveData.class);
        startActivity(i);
    }

    private void CheckData(){
        Intent i1 = new Intent(this, CheckData.class);
        startActivity(i1);
    }*/

    private void loadUser() {
        TextView txt = (TextView) findViewById(R.id.textUser);
        // database handler
        DatabaseHandler db = new DatabaseHandler(getApplicationContext()); 
        // Spinner Drop down elements
        SQLiteDatabase dbs = db.getReadableDatabase();

        Cursor cursor = dbs.rawQuery("SELECT * FROM login", null);
      if (cursor.moveToFirst()) {
         do {
            String emailid=cursor.getString(2); // Here you can get data from table and stored in string if it has only one string.
           txt.setText(emailid);


         } while (cursor.moveToNext());
      }
      if (cursor != null && !cursor.isClosed()) {
         cursor.close();
      }
      if(db!=null)
      {
          db.close();
      }
        // Creating adapter for spinner


    }


    private void DataHama(){
        Intent i2 = new Intent(this, CInputHamaApp.class);
        startActivity(i2);
    }



}

so when i click button logout, the progress dialog show and have a time, example 5 second. how to do that?

the button logout EDIT :

btnLogout.setOnClickListener(new View.OnClickListener() {

          public void onClick(View arg0) {
            // TODO Auto-generated method stub
          logoutUserOperation loguttask = new logoutUserOperation(MainMenu.this);
          loguttask.execute("");

           }

         });

here is the logoutUser function

/**
     * Function to logout user
     * Reset Database
     * */
    public boolean logoutUser(Context context){
        DatabaseHandler db = new DatabaseHandler(context);
        db.resetTables();
        return true;
    }

EDIT: here is the asynctask

private class logoutUserOperation extends AsyncTask<String, Void, Boolean> {
        ProgressDialog progressDialog;
        Context context;
        public logoutUserOperation(Context context){
        this.context=context;
        }
              @Override
              protected void onPreExecute() {
              progressDialog = ProgressDialog.show(context, "", "Logout...");
              }
              @Override
              protected Boolean doInBackground(String... params) {
                    boolean boollogout=userFunctions.logoutUser(context);
                    return boollogout;
              }      

              @Override
              protected void onPostExecute(Boolean result) { 
                  progressDialog.dismiss();
                  if(result){
                        Intent login = new Intent(context,LoginActivity.class);
                        login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                        context.startActivity(login);
                        // Closing dashboard screen
                        context.finish();
                   }else{
                      // your code here...
                   }              
              }
        }

when i try but show error

The method finish() is undefined for the type Context

BR

Alex

EDIT : this is the code to sleep 5 second

protected Boolean doInBackground(String... params) {


                  boolean boollogout=userFunctions.logoutUser(context);

                          try{
                                  Thread.sleep( 5000 );


                          } catch( Exception e ){
                                  Log.i("Logout", e.getMessage() );
                          }

                  return boollogout;


              }      
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:51:47+00:00Added an answer on June 18, 2026 at 10:51 am

    you can show ProgressDialog on button click using AsyncTask as:

    private class logoutUserOperation extends AsyncTask<String, Void, Boolean> {
    ProgressDialog progressDialog;
    Context context;
    public logoutUserOperation(Context context){
    this.context=context;
    }
          @Override
          protected void onPreExecute() {
          progressDialog = ProgressDialog.show(context, "", "Logout...");
          }
          @Override
          protected boolean doInBackground(String... params) {
                boolean boollogout=userFunctions.logoutUser(context);
                return boollogout;
          }      
    
          @Override
          protected void onPostExecute(boolean result) { 
              progressDialog.dismiss();
              if(result){
                    Intent login = new Intent(context, 
                                                 LoginActivity.class);
                    login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    
                    context.startActivity(login);
                    // Closing dashboard screen
                    context.finish();
               }else{
                  // your code here...
               }              
          }
    }
    

    and start AsyncTask as on button click :

    btnLogout.setOnClickListener(new View.OnClickListener() {
    
      public void onClick(View arg0) {
        // TODO Auto-generated method stub
      logoutUserOperation loguttask = new logoutUserOperation(MainMenu.this);
      loguttask.execute("");
    
       }
    
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have followed this tutorial here as mentioned exactly I now try to run
I've read through a few Q&A's here on this subject, but am still confused.
I followed this tutorial . But whenever I try to log in with my
I am using this tutorial to try to replace the default TitleBar with a
I am trying to follow this tutorial ( Using-core-plot-in-an-iphone-application ). When I try to
Two quick questions here... How can I use this example http://try.sencha.com/touch/2.0.0/examples/list-search/ of a searchable
This is a modification of code from the Java tutorial on Concurrency package threads;
I'm pretty sure I followed the procedures for this tutorial accurately but I'm still
Hi i've followed a tutorial and a couple of answers on here but still
I've read this tutorial: http://docs.oracle.com/javase/tutorial/jdbc/basics/transactions.html but I think I'm still missing something. Let us

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.