0

I want to restart my Android app, but I want it to go to a specific activity after the app restart.

I am currently using this code to re launch my app, but it starts back to the first activity. I need it to go to another specific activity.

I made a settings page in my application where users can choose their own app colors. After choosing a color, i need to restart all activities to apply the new theme that the user chose.

code I am using to restart app to first activity:

Intent startActivity = new Intent();
            startActivity.setClass(ProfileSettingsActivity.this,ProfileSettingsActivity.class);
            startActivity(startActivity);
            finish();

3 Answers3

0

easy

Intent intent = new Intent(this, ANOTHER_SPECIFIC_ACTIVITY.class);
this.startActivity(intent);
finish();
Mehran Zamani
  • 831
  • 9
  • 31
  • Don't just write some code. Explain what you've done. – Zeta Feb 12 '17 at 16:55
  • I need the app to reload, not opening a new activity. I need a full app reload to apply my changes.. – Arno Stalpaert Feb 12 '17 at 16:57
  • "I am currently using this code to re launch my app, but it starts back to the first activity. I need it to go to another specific activity." i put ANOTHER_SPECIFIC_ACTIVITY so you can replace it with yours. it is not a good thing to say "full app". you can replace your start activity so that your app restarts and begin fresh. – Mehran Zamani Feb 12 '17 at 18:51
0

In the onCreate() of your first activity, check for whatever conditions you want, and then based on those conditions launch the intent for your specific activity before the setContentView() is called in the first activity.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(CONDITION_1) {
        startActivity(new Intent(this, ActivityA.class));
    } else if(CONDITION_2) {
        startActivity(new Intent(this, ActivityB.class));
    }
    setContentView(R.layout.activity_first);
}
Rachit
  • 3,173
  • 3
  • 28
  • 45
0

Have you tried clearing all activities and launch the new one with Flags?

Intent intent = new Intent(this, NEW_ACTIVITY.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

Doing this, you are clearing all activities previously created and launch NEW_ACTIVITY.class with the new configuration.

Onic Team
  • 1,620
  • 5
  • 26
  • 37
idak_djk
  • 16
  • 4