How to reload an Activity

Asked

Viewed 1,006 times

3

I have the following problem, in my application I have a ListView in act 1, and register with the act 2, but when I finish the registration I also finalize the act 2, with this return to act 1, the problem is that my search method has already loaded my ListView the first time I executed the act 1. How do I call this method again?

  • Call the notifyDataSetChanged() method from your Adapter whenever there are changes to the data. https://www.youtube.com/watch?v=wDBM6wVEO70&t=17m38s

  • thank you so much for this problem I managed to solve, but another one came up if you can help me I thank you ! http://answall.com/questions/154431/manter-os-dados-em-uma-variavel-da-primeira-act-apos-voltar-da-segunda-act-pelo

2 answers

2


You have to explore the life cycle of his Activity using the onResume(). You’d have to put your search back into the method.

@Override
public void onResume(){
    super.onResume();
    // coloque sua busca novamente aqui

}

Life cycle

As the user navigates, exits and returns to your application, the instances Activity in the application transit between different states in the life cycle. For example, when the activity starts for the first time, it is in the foreground of the system and has the focus of the user.

During the process, the Android system calls a series of life cycle methods in the activity, where you define the user interface and other components. If the user executes an action that starts another activity or switches to another application, the system calls another set of life cycle methods in its activity as it gets in the background (where the activity is no longer visible, but the instance and its state remain intact).

inserir a descrição da imagem aqui

Details

0

Register at act2 and close the act2. Do your search in act1 onResume (the method should be called in the same Activity, and it is automatically called when the screen starts or when another screen comes off it) and call meuAdapter.notifyDataSetChanged(); (do not forget to fill the adapt with the new data) that the adapter alone will update. (everything in onresume).

@Override
public void onResume(){ // escreva esse método na act1
    super.onResume();
    // Código da busca
    meuAdapter.notifyDataSetChanged();
}

The interesting thing is that when Voce does this in onResume, every time act1 opens, onResume will run itself. So you don’t have to rewrite the search code on onCreate.

  • thank you so much for this problem I managed to solve, but another one came up if you can help me I thank you ! http://answall.com/questions/154431/manter-os-dados-em-uma-variavel-da-primeira-act-apos-voltar-da-segunda-act-pelo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.