2

For an App I am developing, I want to re-launch the current activity using an intent. So I'm in MainActivity.class and I want to re-launch MainActivity.class using the following:

Intent intent = new Intent(getApplicationContext(), MainActivity.class);

This calls onDestroy() but does not re-launch the activity. Why doesn't this work?

Zero
  • 1,864
  • 3
  • 21
  • 39

4 Answers4

7

If your are in an Activity: this.recreate();

If your are in a Fragment: getActivity.recreate();

Related Links :

How do I restart an Android Activity

how do I restart an activity in android?

Android activity restart

Community
  • 1
  • 1
Rachita Nanda
  • 4,509
  • 9
  • 42
  • 66
4

You could just use:

finish();
startActivity(getIntent());

Which will finish the current activity, and start a new activity with the same intent that you received when the activity was originally created. This should effectively re-launch the activity as is.

Edit:

See Reload activity in Android

Community
  • 1
  • 1
biddulph.r
  • 5,226
  • 3
  • 32
  • 47
1

Just do this:

  Intent i=getIntent();//This simply returns the intent in which the current Activity is started
  finish();//This would simply stop the current Activity.
  startActivity(i);//This would start a new Activity.
Sled
  • 18,541
  • 27
  • 119
  • 168
Dulanga
  • 1,326
  • 7
  • 15
0

Include this one ...

startActivity(intent); 
Ganesh Rengarajan
  • 2,006
  • 13
  • 26