I want to program my android app to refresh its current activity on ButtonClick. I have one button on the top of the activity layout which will do the job. When I click on button the current activity should reload again - just like a device restart.
Thanks
Start with an intent your same activity and close the activity . Intent refresh = new Intent(this, Main. class); startActivity(refresh);//Start the same Activity finish(); //finish Activity.
onCreate is used to start an activity. super is used to call the parent class constructor. setContentView is used to set the xml.
Starting an activity You can start a new instance of an Activity by passing an Intent to startActivity() . The Intent describes the activity to start and carries any necessary data. If you want to receive a result from the activity when it finishes, call startActivityForResult() .
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
public void onClick (View v){ Intent intent = getIntent(); finish(); startActivity(intent); }
You may try this
finish(); startActivity(getIntent());
This question was asked before: How do I restart an Android Activity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With