The intent does not want to work to open another activity

0

Good afternoon friends I have a problem with the intents I do not know what's wrong I want to open another activity from a class obviously passing the context of the activity from where I want to pass it.

public class Informe implements Response.ErrorListener, Response.Listener<JSONObject> {


//Propiedades que ayudan a conectarnos con el webservices

 RequestQueue request;
 JsonObjectRequest jsonObjectRequest;

 //El contexto donde se maneja este informe de la aplicacion

Context InformarTrabajoContext;

//Propiedades propias del Informe
private String Conclusion;
private String DescripcionDelTrabajo;
private String Estad;
private int id_informe ;
private String Necesidades;

private int registro_empleado;

public Informe(String conclusion, String descripcionDelTrabajo, String estad, int id_informe, String necesidades, int registro_empleado) {
    Conclusion = conclusion;
    DescripcionDelTrabajo = descripcionDelTrabajo;
    Estad = estad;
    this.id_informe = id_informe;
    Necesidades = necesidades;
    this.registro_empleado = registro_empleado;
}


public Informe() {
}



public int getRegistro_empleado() {
    return registro_empleado;
}

public void setRegistro_empleado(int registro_empleado) {
    this.registro_empleado = registro_empleado;
}

public String getConclusion() {
    return Conclusion;
}

public void setConclusion(String conclusion) {
    Conclusion = conclusion;
}

public String getDescripcionDelTrabajo() {
    return DescripcionDelTrabajo;
}

public void setDescripcionDelTrabajo(String descripcionDelTrabajo) {
    DescripcionDelTrabajo = descripcionDelTrabajo;
}

public String getEstad() {
    return Estad;
}

public void setEstad(String estad) {
    Estad = estad;
}

public int getId_informe() {
    return id_informe;
}

public void setId_informe(int id_informe) {
    this.id_informe = id_informe;
}

public String getNecesidades() {
    return Necesidades;
}

public void setNecesidades(String necesidades) {
    Necesidades = necesidades;
}

 public void RegistrarInforme(Context contexto){

     this.InformarTrabajoContext = contexto;
     this.request = Volley.newRequestQueue(this.InformarTrabajoContext);
     llamarAlWebSerices();

 }

private void llamarAlWebSerices() {

    String url = "http://192.168.7.119/WebServicesGestionAsistencia/AgregarInforme.php?conclusion="+this.Conclusion+"&descripcion="+this.DescripcionDelTrabajo+"&necesidades="+this.Necesidades+"&registro_empleado="+this.registro_empleado+"&Estado="+this.Estad;
    url = url.replace(" ","%20");
    this.jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,url,null,this,this);
    this.request.add(jsonObjectRequest);
}

@Override
public void onErrorResponse(VolleyError error) {
    //Toast.makeText(this.InformarTrabajoContext,"Agregado exitosamente"+error.getMessage(),Toast.LENGTH_LONG).show();
    Intent VolverVentanaAnterior = new Intent(this.InformarTrabajoContext, InformacionDelEmpleado.class);
    this.InformarTrabajoContext.startActivity(VolverVentanaAnterior);
}

@Override
public void onResponse(JSONObject response) {
     //Toast.makeText(this.InformarTrabajoContext,"Informe agregado correctamente",Toast.LENGTH_LONG).show();
    Intent VolverVentanaAnterior = new Intent(this.InformarTrabajoContext, MainActivity.class);
    this.InformarTrabajoContext.startActivity(VolverVentanaAnterior);
}

}

I have the context that I receive as a parameter when it is called Record Report and good about that context work and look at the method onResponse and onErrorResponse I want to open another activity but I get an error I do not know what happens because it will be thank you very much.

Here below I pass the code that is from where I call the RecordReport method:

public class InformarTrabajo extends AppCompatActivity implements View.OnClickListener {


// Objetos del form

private EditText etDescripcion,etConclusion,etNecesidades;
private Button btnEnviarInforme;
private Spinner spinnerEstado;

//Objeto Informe

private Informe informeDeEmpleado;

//Registro del empleado

int registro_empleado;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_informar_trabajo);
    recuPerarRegistro();
    InicializarObjetosForm();
    setButtonEvents();

}

private void setButtonEvents() {

     this.btnEnviarInforme.setOnClickListener(this);

}
@Override
public void onClick(View v) {
    llenarObjetoInforme();
    this.informeDeEmpleado.RegistrarInforme(InformarTrabajo.this);

}



private void llenarObjetoInforme() {

      this.informeDeEmpleado = new Informe();
      this.informeDeEmpleado.setConclusion(this.etConclusion.getText().toString());
      this.informeDeEmpleado.setDescripcionDelTrabajo(this.etDescripcion.getText().toString());
      this.informeDeEmpleado.setEstad(this.spinnerEstado.getSelectedItem().toString());
      this.informeDeEmpleado.setNecesidades(this.etNecesidades.getText().toString());
      this.informeDeEmpleado.setRegistro_empleado(this.registro_empleado);

}

private void InicializarObjetosForm() {
    this.etDescripcion = (EditText)findViewById(R.id.etDescripcionTrabajoInforme);
    this.etConclusion = (EditText) findViewById(R.id.etConclusionInformeEmpleado);
    this.etNecesidades = (EditText)findViewById(R.id.etNecesidadesInformeEmpleado);
    this.spinnerEstado = (Spinner) findViewById(R.id.spinnerEstadoInforme);
    this.btnEnviarInforme = (Button) findViewById(R.id.BtnEnviarInformeEmpleado);
}

private void recuPerarRegistro() {

     this.registro_empleado = getIntent().getExtras().getInt("registroEmleado");
    Toast.makeText(this,String.valueOf(this.registro_empleado),Toast.LENGTH_LONG).show();

}

}

    
asked by Ijsud 24.09.2018 в 22:36
source

1 answer

0

try in the onResponse to put this code that what it does is open the activity you want.

  Intent intent = new Intent(v.getContext(), miActivity.class);
            startActivityForResult(intent, 0);
    
answered by 24.09.2018 в 23:22