Problem With User Login api

I am using Backendless.UserService.login for logging in users. But problem is that it is showing no error and also user is not logged in.

Here is the code i am using.

package paizy.blackdogs.paizy;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.backendless.Backendless;
import com.backendless.BackendlessUser;
import com.backendless.async.callback.AsyncCallback;

/**
 * Created by Milan Marwadi on 08-02-2016.
 */
public class Login extends Activity implements View.OnClickListener {

    Button login_btn;
    EditText email;
    EditText passwd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        Backendless.initApp(this, BackendSettings.Application_Id, BackendSettings.SecretKey, BackendSettings.appVersion);

        login_btn = (Button) findViewById(R.id.login_button);
        login_btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();

        switch (id){

            case R.id.login_button:

                email = (EditText) findViewById(R.id.email);
                passwd = (EditText) findViewById(R.id.password);

                CharSequence email_id = email.getText();
                CharSequence password = passwd.getText();

               


                    LoadingCallback<BackendlessUser> loginCallback = createLoginCallback();
                    loginCallback.showLoading();
                Toast.makeText(this,"Logged in : Name is ",Toast.LENGTH_LONG).show();
                    loginUser(email_id.toString(), password.toString(), loginCallback);
                Toast.makeText(this,"Second",Toast.LENGTH_LONG).show();

        }

    }

    private LoadingCallback<BackendlessUser> createLoginCallback() {
        return new LoadingCallback<BackendlessUser>(this,"Sending Login info")
        {
            public void handleResponse(BackendlessUser loggedUser){

                super.handleResponse(loggedUser);
                Toast.makeText(Login.this,String.format("Logged in : Name is %s", loggedUser.getObjectId()),Toast.LENGTH_LONG).show();
            }
        };

    }

    private void loginUser(String s, String s1, AsyncCallback<BackendlessUser> loginCallback) {
        Backendless.UserService.login(s,s1,loginCallback);
    }


}

Hi Milan,

I think the problem might be in the LoadingCallback class. Could you please show its implementation?

Regards,
Mark

Here is the code of LoadingCallback which i am also using for Registering users.

package paizy.blackdogs.paizy;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;

import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessFault;

/**
 * Created by Milan Marwadi on 04-02-2016.
 */
public class LoadingCallback<T> implements AsyncCallback<T> {

    private Context context;
    private ProgressDialog progressDialog;

    public LoadingCallback(Context context) {
        this(context, "Loading...");
    }


    public LoadingCallback(Context context, String loadingMessage) {

        this.context = context;
        progressDialog = new ProgressDialog(context);
        progressDialog.setMessage(loadingMessage);
    }

    public void handleResponse(T response) {
        progressDialog.dismiss();
    }

    public void handleFault(BackendlessFault fault) {
        progressDialog.dismiss();
//        DialogHelper.createErrorDialog(context, "BackendlessFault", fault.getMessage()).show();
    }

    public void showLoading(){
        progressDialog.show();
    }

    public void hideLoading(){
        progressDialog.dismiss();
    }
}


Hi Milan,

How do you know the user is not logged in? Is it because the progress dialog is not going away? Have you tried putting a breakpoint on the following lines in the LoadingCallback class?:

progressDialog.dismiss();

Regards,
Mark

the loading dialog which appears dismisses if user touches somewhere on screen … meanwhile user can click some other option leading to force close the app

is there anyway to make the loading dialog non dismissable on click ?

Since the dialog is handled within your code, you should have all the controls over the component and how it interacts with the users. In other words, there is absolutely no code in Backendless SDK that does anything with the dialog.