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 9071131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:50:22+00:00 2026-06-16T17:50:22+00:00

i try this Tutorial to Login with PHP, MySQL and SQLite and it works.

  • 0

i try this Tutorial

to Login with PHP, MySQL and SQLite and it works.

but i want to add a progressdialog when the login is in progress.

this is my login activity before add asynctask and works

package com.app.DatabaseSample;


import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.app.library.DatabaseHandler;
import com.app.library.UserFunctions;

public class LoginActivity extends Activity {
    Button btnLogin;
    Button btnLinkToRegister;
    EditText inputUsername;
    EditText inputPassword;
    TextView loginErrorMsg;

    // JSON Response node names
    private static String KEY_SUCCESS = "success";
    private static String KEY_ERROR = "error";
    private static String KEY_ERROR_MSG = "error_msg";
    private static String KEY_UID = "uid";
    private static String KEY_NAME = "name";
    private static String KEY_EMAIL = "email";
    private static String KEY_CREATED_AT = "created_at";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        // Importing all assets like buttons, text fields
        inputUsername = (EditText) findViewById(R.id.loginUsername);
        inputPassword = (EditText) findViewById(R.id.loginPassword);
        btnLogin = (Button) findViewById(R.id.btnLogin);
        loginErrorMsg = (TextView) findViewById(R.id.login_error);

     // Login button Click Event
        btnLogin.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                String email = inputUsername.getText().toString();
                String password = inputPassword.getText().toString();
                UserFunctions userFunction = new UserFunctions();
                Log.d("Button", "Login");
                JSONObject json = userFunction.loginUser(email, password);

                // check for login response
                try {
                    if (json.getString(KEY_SUCCESS) != null) {
                        loginErrorMsg.setText("");
                        String res = json.getString(KEY_SUCCESS); 
                        if(Integer.parseInt(res) == 1){
                            // user successfully logged in
                            // Store user details in SQLite Database
                            DatabaseHandler db = new DatabaseHandler(getApplicationContext());
                            JSONObject json_user = json.getJSONObject("user");

                            // Clear all previous data in database
                            userFunction.logoutUser(getApplicationContext());
                            db.addUser(json_user.getString(KEY_NAME), json_user.getString(KEY_EMAIL), json.getString(KEY_UID), json_user.getString(KEY_CREATED_AT));                        

                            // Launch Dashboard Screen
                            Intent dashboard = new Intent(getApplicationContext(), DatabaseSample.class);

                            // Close all views before launching Dashboard
                            dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(dashboard);

                            // Close Login Screen
                            finish();
                        }else{
                            // Error in login
                            loginErrorMsg.setText("Incorrect username/password");
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });

    }

}

and after i edit with asyntask

there is my login activity

package com.app.DatabaseSample;


import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.app.library.DatabaseHandler;
import com.app.library.JSONParser;
import com.app.library.UserFunctions;



public class LoginActivity extends Activity {
    Button btnLogin;
    Button btnLinkToRegister;
    EditText inputUsername;
    EditText inputPassword;
    TextView loginErrorMsg;


    // JSON Response node names
    private static String KEY_SUCCESS = "success";
    private static String KEY_ERROR = "error";
    private static String KEY_ERROR_MSG = "error_msg";
    private static String KEY_UID = "uid";
    private static String KEY_NAME = "name";
    private static String KEY_EMAIL = "email";
    private static String KEY_CREATED_AT = "created_at";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        // Importing all assets like buttons, text fields
        inputUsername = (EditText) findViewById(R.id.loginUsername);
        inputPassword = (EditText) findViewById(R.id.loginPassword);
        btnLogin = (Button) findViewById(R.id.btnLogin);
        loginErrorMsg = (TextView) findViewById(R.id.login_error);

     // Login button Click Event
        btnLogin.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                readLogin(view);
            }
        });

    }

    private class ProcessLogin extends AsyncTask<String, String, String> {

        private ProgressDialog dialog;
        private ProgressDialog pDialog;
        protected Context applicationContext;


        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(LoginActivity.this);
            pDialog.setMessage("Loading User ...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        @Override
        protected String doInBackground(String... args) {
            inputUsername = (EditText) findViewById(R.id.loginUsername);
            inputPassword = (EditText) findViewById(R.id.loginPassword);
            String email = inputUsername.getText().toString();
            String password = inputPassword.getText().toString();
            UserFunctions userFunction = new UserFunctions();
            JSONObject json = userFunction.loginUser(email, password);

            Log.d("Button", "Login");

            try {
                if (json.getString(KEY_SUCCESS) != null) {
                    loginErrorMsg.setText("");
                    String res = json.getString(KEY_SUCCESS); 
                    if(Integer.parseInt(res) == 1){
                        // user successfully logged in
                        // Store user details in SQLite Database
                        DatabaseHandler db = new DatabaseHandler(getApplicationContext());
                        JSONObject json_user = json.getJSONObject("user");

                        // Clear all previous data in database
                        userFunction.logoutUser(getApplicationContext());
                        db.addUser(json_user.getString(KEY_NAME), json_user.getString(KEY_EMAIL), json.getString(KEY_UID), json_user.getString(KEY_CREATED_AT));                        

                        // Launch Dashboard Screen
                        Intent dashboard = new Intent(getApplicationContext(), DatabaseSample.class);

                        // Close all views before launching Dashboard
                        dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(dashboard);

                        // Close Login Screen
                        finish();
                    }else{
                        // Error in login
                        loginErrorMsg.setText("Incorrect username/password");
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;

        }

        @Override
        protected void onPostExecute(String file_url) {
            // dismiss the dialog after getting all products
            pDialog.dismiss();
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    /**
                     * Updating parsed JSON data into ListView
                     * */
                    Intent dashboard = new Intent(getApplicationContext(), DatabaseSample.class);
                    dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(dashboard);

                    // Close Login Screen
                    finish();
                }
            });

        }
      }

    public void readLogin(View view) {
        new ProcessLogin().execute();

    // check for login response

  }
}

i try to run but error.

this is my logcat.

01-02 12:10:42.445: ERROR/JSON(4021): {"tag":"login","success":0,"error":1,"error_msg":"Incorrect email or password!"}
01-02 12:10:42.453: DEBUG/Button(4021): Login
01-02 12:10:42.453: WARN/dalvikvm(4021): threadid=9: thread exiting with uncaught exception (group=0x40015560)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021): FATAL EXCEPTION: AsyncTask #1
01-02 12:10:42.460: ERROR/AndroidRuntime(4021): java.lang.RuntimeException: An error occured while executing doInBackground()
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at java.lang.Thread.run(Thread.java:1019)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at android.view.ViewRoot.checkThread(ViewRoot.java:2932)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at android.view.ViewRoot.invalidateChild(ViewRoot.java:642)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:668)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at android.view.ViewGroup.invalidateChild(ViewGroup.java:2511)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at android.view.View.invalidate(View.java:5279)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at android.widget.TextView.checkForRelayout(TextView.java:5528)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at android.widget.TextView.setText(TextView.java:2730)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at android.widget.TextView.setText(TextView.java:2598)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at android.widget.TextView.setText(TextView.java:2573)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at com.app.DatabaseSample.LoginActivity$ProcessLogin.doInBackground(LoginActivity.java:99)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at com.app.DatabaseSample.LoginActivity$ProcessLogin.doInBackground(LoginActivity.java:1)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
01-02 12:10:42.460: ERROR/AndroidRuntime(4021):     ... 4 more
01-02 12:10:42.468: WARN/ActivityManager(1308):   Force finishing activity com.app.DatabaseSample/.LoginActivity
01-02 12:10:42.585: WARN/IInputConnectionWrapper(4021): showStatusIcon on inactive InputConnection
01-02 12:10:42.585: WARN/InputManagerService(1308): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@40683810 (uid=10040 pid=4021)
01-02 12:10:43.320: ERROR/WindowManager(4021): Activity com.app.DatabaseSample.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40529e48 that was originally added here
01-02 12:10:43.320: ERROR/WindowManager(4021): android.view.WindowLeaked: Activity com.app.DatabaseSample.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40529e48 that was originally added here
01-02 12:10:43.320: ERROR/WindowManager(4021):     at android.view.ViewRoot.<init>(ViewRoot.java:258)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at android.app.Dialog.show(Dialog.java:241)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at com.app.DatabaseSample.LoginActivity$ProcessLogin.onPreExecute(LoginActivity.java:83)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at android.os.AsyncTask.execute(AsyncTask.java:391)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at com.app.DatabaseSample.LoginActivity.readLogin(LoginActivity.java:156)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at com.app.DatabaseSample.LoginActivity$1.onClick(LoginActivity.java:63)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at android.view.View.performClick(View.java:2485)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at android.view.View$PerformClick.run(View.java:9080)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at android.os.Handler.handleCallback(Handler.java:587)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at android.os.Looper.loop(Looper.java:130)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at android.app.ActivityThread.main(ActivityThread.java:3683)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at java.lang.reflect.Method.invokeNative(Native Method)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at java.lang.reflect.Method.invoke(Method.java:507)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-02 12:10:43.320: ERROR/WindowManager(4021):     at dalvik.system.NativeStart.main(Native Method)

how to add a progress dialog in my login activity?

BR

Alex

  • 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-16T17:50:23+00:00Added an answer on June 16, 2026 at 5:50 pm

    CalledFromWrongThreadException: Only the original thread that created
    a view hierarchy can touch its views.

    because currently you are trying to Access UI Elements from doInBackground of ProcessLogin AsyncTask .

    just move all Ui elements from doInBackground to onPostExecute for updating Ui doInBackground execution complete

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed this tutorial . But whenever I try to log in with my
I followed this video tutorial but i am stuck.When i click on the login
I try to follow this tutorial, but I can't get it to work: http://weierophinney.net/matthew/archives/246-Using-Action-Helpers-To-Implement-Re-Usable-Widgets.html
I try add example from http://ellislab.com/codeigniter/user_guide/tutorial/news_section.html to my site, this is code: news_model <?php
I am using this tutorial to try to replace the default TitleBar with a
I have followed this tutorial here as mentioned exactly I now try to run
I am trying to follow this tutorial ( Using-core-plot-in-an-iphone-application ). When I try to
I'm following a tutorial: http://visionmasterdesigns.com/tutorial-create-a-login-system-in-ruby-on-rails/ to create a login page when I try to
When I try to follow this tutorial to install Google-auth2 on my Django 1.4
I am following this tutorial for sending Emails from My App. When i try

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.