Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android refresh current activity [duplicate]

Tags:

android

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

like image 639
Android_Code_Chef Avatar asked Jul 01 '11 12:07

Android_Code_Chef


People also ask

How to refresh data on activity in android?

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.

What is onCreate Method in android?

onCreate is used to start an activity. super is used to call the parent class constructor. setContentView is used to set the xml.

What does startActivity do?

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() .

What does finish () do in Android?

On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.


2 Answers

public void onClick (View v){     Intent intent = getIntent();     finish();     startActivity(intent); } 
like image 173
Otra Avatar answered Oct 06 '22 01:10

Otra


You may try this

finish(); startActivity(getIntent()); 

This question was asked before: How do I restart an Android Activity

like image 24
gregory561 Avatar answered Oct 06 '22 01:10

gregory561