1

I wanna change starting activity after the user will make certain instructions. Let's say that for now MainActivity.java starts every time when the user runs the app. I wanna change that to MainActivity2.java after the user will click on specified button in app. I'm trying to do that by using shared preferences but can't figure it out how to make it. I know that I need a context to start an activity, so do I need to create empty activity and then just put code with "if" instruction to run proper activity?

I already tried to do that on a simple java class (non-activity class) but it can't be done since it does not extend "AppCompatActivity".

Tholvnar
  • 43
  • 5
  • Try looking at [Programmatically change launcher activity](https://stackoverflow.com/questions/12765118/programmatically-change-launcher-activity?adlt=strict&toWww=1&redig=0DD3BAF58C5749C08D836C76C66898B4). – Alias Cartellano Oct 26 '22 at 16:54

1 Answers1

0

You can keep your existant launcher Activity, in the onCreate methode, check for your condition, change the Activity :

@Override
public void onCreate(Bundle b){
super.onCreate();
if(your_condition){
startActivity(new Intent(this, MainActivity2.class);
finish();
}
setContentView(R.layout.main_activity1);
}
Gaya Touak
  • 56
  • 5