When executing an Activity, I want the execution to wait for the closing to continue, or sequentially execute the code

1

How do I execute an activity and after closing it continue to execute the code where it stopped, for example:

    listmarcacoes.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView adapter, View viw, int posicao,long id) {
            cursor.moveToPosition(posicao);
            Intent intent = new Intent(getActivity(), EdicaoMarcacao.class);
            Bundle params = new Bundle();
            String resposta = cursor.getString(1).toString();
            if(CalculoHora.isHojeData(resposta)){
                Toast.makeText(getActivity(), "Use a aba RESGISTRO para marcações do dia!", Toast.LENGTH_SHORT).show();
            } else {
                params.putString("diafiltro", resposta);
                intent.putExtras(params);
                //  Aqui quero que a execução aguarde a activity ser executada!
                startActivity(intent);
                //  Aqui a execução continua apos o encerramento da actitity!
                // Executanto posteriormente o metodo lista()
                lista();
            }
        }            
    });

I need it to be this way because when I call the activity "EditMarch" it changes the values of listview, so when I close the second screen I want to update the first one.

    
asked by anonymous 21.10.2014 / 23:38

1 answer

1

You can use:

listmarcacoes.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView adapter, View viw, int posicao,long id) {
        cursor.moveToPosition(posicao);
        Intent intent = new Intent(getActivity(), EdicaoMarcacao.class);
        Bundle params = new Bundle();
        String resposta = cursor.getString(1).toString();
        if(CalculoHora.isHojeData(resposta)){
            Toast.makeText(getActivity(), "Use a aba RESGISTRO para marcações do dia!", Toast.LENGTH_SHORT).show();
        } else {
            params.putString("diafiltro", resposta);
            intent.putExtras(params);
            startActivityForResult(intent, 9);//9 é o requestCode número inteiro para a identificação
        }
    }            
});

Then overwrite method :

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == 9 && resultCode == RESULT_OK) {

        Bundle params = data.getExtras();
        String resposta = params.getString("diafiltro");
        lista();
    }
}

In the Edit activity, click on

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle params = getIntent().getExtras();
    String resposta = params.getString("diafiltro");
}

Then make the changes you want and when you finish executing the activity EditChange.class do: (obs: in EditChange.class)

Bundle params = new Bundle();
params.putString("diafiltro", resposta);
intent.putExtras(params);
setResult(RESULT_OK, intent);
finish();
    
22.10.2014 / 01:17