saintjab
saintjab

Reputation: 1642

How to change MAIN activity during runtime

I have two activities (LoginActivity and MainActivity) with the LoginActivity being the MAIN and LAUNCHER in the android manifest file. Once the App launches, I don't want to go back to the LoginActivity even when Back button is pressed. How can I ensure the MainActivity becomes the main/ home activity though its not in the manifest as the MAIN during run time.

Upvotes: 1

Views: 1496

Answers (3)

KunamiPT
KunamiPT

Reputation: 112

Just use finish() of the activity class after starting new intent on LoginActivity

Intent intent = new Intent(this, HomeActivity.Class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish(); // Call once you redirect to another activity

Upvotes: 1

nobalG
nobalG

Reputation: 4620

Just call finish() method of the Activity class on successfull log in.You will never see that Activity again in your application (obviously you must have to apply logic's to make it appear again, when some user logs out)

Do it like this When user is authenticated by correct username-password combination

Intent i=new Intent(LogInActivity.this,HomeActivity.class);
startActivity(i);
finish();

Then the previous activity (LogInActivity) will be finished.

Upvotes: 4

Marcin Mikołajczyk
Marcin Mikołajczyk

Reputation: 731

try adding android:noHistory="true" to your <activity> tag in android manifest xml file

Upvotes: 0

Related Questions