Refresh activity from a later activity

2

I have an app in which I launch a settings activity in which you can configure the w-fi and the url to show in the first activity. The problem is that, when you go back and return to the beginning app, the changes are not automatically shown. How can I do it? Is there any way to detect that you have returned from the second activity? If there is, would it be worth to execute this code when it detects that it has returned to the first activity?

public void RestartActivity()
    {
        Intent intent = getIntent();
        finish();
        startActivity(intent);
    }

Without doing this, would there be any possibility to rerun the OnCreate?

    
asked by pepito 26.07.2017 в 14:03
source

2 answers

4

About write the onResume() method of the activity that is run when the Activity becomes active again:

public class MainActivity extends Activity
{

   //...


  @Override
  public void onResume()
  {
    // ejecuta el codigo aqui...
  }
} 

In your case, you were in the Activity_A and you started the Activity_B and so the Activity_A is inactive. Now, when you return to Activity_A , the method onCreate does not run again because it was already created (remember that it is inactive, not finalized), so the method onResume() is executed. This is so long as we do not execute the finish() method that ends the Activity .

    
answered by 26.07.2017 / 14:17
source
2
  

The problem is that, when you go back and go back to the beginning app, the   changes are not shown automatically.

If you return to a Activity previously loaded, the method onResume() is called, this is where you can add the code necessary for the update, this you can see in the life cycle of the Activity

  

Is there any way to detect that you have returned to the activity?

You can see on the site several questions where this is referenced.

 @Override
protected void onResume() {
    super.onResume();

   //Carga Activity. 

}
    
answered by 26.07.2017 в 18:05