Reputation: 1479
I have a LoginActivity (this is the main activity) and after the user logs in it redirects him to another activity, howerver when he presses the back button it goes back to the login activity. I tried using this:
StartActivity(typeof(FragmentRendererActivity));
Finish();
and this:
StartActivity(new Intent(this, typeof(FragmentRendererActivity)));
Finish();
and this:
Intent intent = new Intent(this, typeof(FragmentRendererActivity));
intent.AddFlags(ActivityFlags.NoHistory);
StartActivity(intent);
and this:
Intent intent = new Intent(this, typeof(FragmentRendererActivity));
intent.AddFlags(ActivityFlags.ClearTop);
intent.AddFlags(ActivityFlags.ClearTask);
intent.AddFlags(ActivityFlags.NewTask);
StartActivity(intent);
Finish();
and this:
<application android:label="Homecheck" android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<activity android:name="LoginActivity" android:noHistory="true" android:launchMode="singleTask" />
</application>
...but nothing worked. The closest thing I was able to get to was that I log in, I go to Activity B, I press the back button and the app exits(Paused state). I resume it and, you guessed it, I'm back at the Login Activity. So is there a way to properly get rid of an activity in the back stack ? P.S. Maybe the problem is that my LoginActivity is the main activity ?
Upvotes: 0
Views: 3041
Reputation: 2453
If Login is your MainActivity, everytime the app closes and opens it will be the first screen the users sees. Use a splash screen that can check if your user has already been authenticated and redirect them from there. The behaviour you talk about is the expected behaviour
Adding NoHistory = true in the attributes ontop of the class will remove it from the back stack
[Activity(Label = "SampleApp", NoHistory = true)]
public class LoginActivty : Activity
{
}
Also another thing you can try and clear top activity
var intent = new Intent(this, typeof(SampleActivity));
intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask | ActivityFlags.NewTask);
StartActivity(intent);
Finish();
Upvotes: 3