Implement a Snackbar inside an Asynctask

0

I have a Asynctask that basically performs the task of Login and when the credentials are correct and pass the following Activity mustre a message of type Snackbar I share the method where I think it should go ...

 protected void onPostExecute(String result) {

        // este método se ejecutará en el subproceso de la interfaz de usuario
        pdLoading.dismiss();

        if(result.equalsIgnoreCase("true"))
        {
            // si sale bien el proceso y se legea correctamente pasa a la activity menuexpositor y finaliza login expositor
            // para que no pueda volver atras. sino que volvera el menu princial
            final String email = etEmail.getText().toString();

            Toast.makeText(getApplicationContext(),"Bienvenido/a: "+email,Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(formularioExpositor.this,MenuExpositor.class);
            startActivity(intent);
            formularioExpositor.this.finish();

        }else if (result.equalsIgnoreCase("false")){

            final AlertDialog.Builder alertaDeError = new AlertDialog.Builder(formularioExpositor.this);
            alertaDeError.setTitle("Error");
            alertaDeError.setMessage("Credenciales incorrectas.");
            alertaDeError.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            alertaDeError.create();
            alertaDeError.show();

        } else if (result.equalsIgnoreCase("exception") || result.equalsIgnoreCase("unsuccessful")) {


            final AlertDialog.Builder alertaDeError2 = new AlertDialog.Builder(formularioExpositor.this);
            alertaDeError2.setTitle("Error");
            alertaDeError2.setMessage("Ha ocurrido un error inesperado. Intente nuevamente. Verifique su conexión a Internet");
            alertaDeError2.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            alertaDeError2.create();
            alertaDeError2.show();


        }
    }

As you can see I'm using a Toast to show the message. Any suggestions?

    
asked by Ashley G. 26.12.2016 в 19:07
source

1 answer

2

First you must create in your layout

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"       
    android:layout_height="match_parent"       
    android:layout_alignParentBottom="true"       
    android:layout_centerHorizontal="true"       
    android:id="@+id/snackbarExample">
</android.support.design.widget.CoordinatorLayout>

In your Activity create the following variable

View coordinatorLayoutView;

In the method onCreate of your Activity initializes the variable:

coordinatorLayoutView = findViewById(R.id.snackbarExample);

And then create in your method onPost

Snackbar snackbar = Snackbar.make(coordinatorLayoutView, "Bienvenido/a: "+email, Snackbar.LENGTH_LONG);
snackbar.show();
    
answered by 26.12.2016 / 19:11
source