Reloading an activity

3

I have the following problem, in my application I have a ListView in act 1 , and I make a register in act 2 , however when I finish the registration I also end 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 act 1 . How do I call this method again?

    
asked by anonymous 22.09.2016 / 05:03

2 answers

2

You have to explore the life cycle from its Activity using onResume() . You would have to put your search again within 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 Activity instances in the application transit between different states in the lifecycle. For example, when the activity starts for the first time, it is in the foreground in the system and has the user focus.

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

Details

22.09.2016 / 14:15
0

Register for act2 and quit act2. Do your search on act1's onResume (the method must be called in the same activity, and it is automatically called when the screen starts or when another screen exits) and call meuAdapter.notifyDataSetChanged(); (do not forget to fill it in with the new data) that the adapter alone will update itself. (all 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 you do this in onResume, every time act1 opens, onResume will run on its own. So you do not need to rewrite the onCreate search code.

    
22.09.2016 / 15:17