I have an Android application. I am making a loading screen with a progress bar.
I entered a delay in the onCreate method. When the timer finishes, I want to finis
If you are doing a loading screen, just set the parameter to not keep it in activity stack. In your manifest.xml, where you define your activity do:
<activity android:name=".LoadingScreen" android:noHistory="true" ... />
And in your code there is no need to call .finish() anymore. Just do startActivity(i);
There is also no need to keep a instance of your current activity in a separate field. You can always access it like LoadingScreen.this.doSomething()
instead of private LoadingScreen loadingScreen;
I found many answers but not one is simple... I hope this will help you...
try{
Intent intent = new Intent(CurrentActivity.this, NewActivity.class);
startActivity(intent);
} finally {
finish();
}
so, Very simple logic is here, as we know that in java we write code that has some chances of exception in a try block and handle that exception in catch block but in finally block we write code that has to be executed in any cost (Either the exception comes or not).