Current Android Update Activity

I want to program an Android app to update its current activity in ButtonClick. I have one button at the top of the activity layout that will do the job. When I press the button, the current activity should restart again - just like rebooting the device.

thank

+47
android
Jul 01 '11 at 12:30
source share
11 answers
public void onClick (View v){ Intent intent = getIntent(); finish(); startActivity(intent); } 
+101
Jul 01 2018-11-12T00:
source share

You can try this

 finish(); startActivity(getIntent()); 

This question has been asked before: How to restart an Android action.

+34
Jul 01 2018-11-11T00:
source share

In an exercise, you can call recreate() to "recreate" activity (API 11 +)

+16
Apr 15 '14 at 9:40
source share

This is a refresh button button, but it works well in my application. in finish () you kill instances

 public void refresh(View view){ //refresh is onClick name given to the button onRestart(); } @Override protected void onRestart() { // TODO Auto-generated method stub super.onRestart(); Intent i = new Intent(lala.this, lala.class); //your class startActivity(i); finish(); } 
+11
Sep 25 '12 at 15:33
source share

that's what seemed to me here .

Just use it or add it to the static class helper and just call it from anywher in your project.

 /** Current Activity instance will go through its lifecycle to onDestroy() and a new instance then created after it. */ @SuppressLint("NewApi") public static final void recreateActivityCompat(final Activity a) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { a.recreate(); } else { final Intent intent = a.getIntent(); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); a.finish(); a.overridePendingTransition(0, 0); a.startActivity(intent); a.overridePendingTransition(0, 0); } } 
+6
Jun 12 '15 at 20:05
source share

It should start again and delete all instances of the previous current activity.

No, it should not be.

It should update its data in place (e.g. requery() Cursor ). Then there will be no β€œcases of previous current activities” that could be worried about.

+3
Jul 01 '11 at 12:40
source share

You can try the following:

  CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); Intent intent= new Intent(YourCurrent.this, YourCurrent.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); 
+3
Sep 13 '14 at 8:37
source share

You can use:

 startActivity(MyClass.this, MyClass.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
+2
Jun 05 '13 at 4:49
source share

The easiest way is to call onCreate(null); , and your activity will be like new.

+1
Jan 10 '13 at 0:32
source share

From the dialogue to the activity you want to update. If this is not the first activity!
Example: mainActivity β†’ objectActivity β†’ dialog
In your dialog class:

  @Override public void dismiss() { super.dismiss(); getActivity().finish(); Intent i = new Intent(getActivity(), objectActivity.class); //your class startActivity(i); } 
0
Apr 01 '16 at 19:22
source share

Try

Easy way

  Intent intent=new Intent(Current_Activity.this,Current_Activity.class); startActivity(intent); finish(); 
0
Jun 12 '17 at 7:48
source share



All Articles