Reputation: 65
I'd like to make my splash screen more smooth. I maked splash screen after I read this link. However, when I finish SplashActivity and intent to MainActivity, I feel SplashActivity finish too early, I saw screen saver of my device before MainActivity show (I estimate the delay to be 0.5s). What I want is the MainActivity ready before the SplashActivity finish.
I tried the solutio that is set flags FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TASK in my Intent, but it's not make smooth.
Below is the code for transtion between 2 activities:
private void transitionActivity() {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
And Manifest file:
<activity
android:name=".SplashActivity"
android:launchMode="singleTask"
android:theme="@style/SplashScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:theme="@style/AppThemeNoActionBar" />
Upvotes: 1
Views: 1559
Reputation: 65
First of all, I want to thank everyone who has answered me as well as commented on my question. There is one answer of @MOF (answer link), it does not solve the problem, but it helps me think of a new way, and this new way helps my problem no longer exist. My way is:
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
finish();
}
}, getResources().getInteger(android.R.integer.config_mediumAnimTime));
Thank all of you!
Upvotes: 1
Reputation: 163
maybe the point is he want to give delay in splash screen
if that so you can do that using Handler()
int SplashDuration = 2000;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(splashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
}, SplashDuration);
and if that still to fast or to slow for you, you can change the time at "SplashDuration"
Upvotes: 0
Reputation: 9
you can using https://developer.android.com/reference/android/os/AsyncTask.html for do it. make logic when splashscreen until 5 seconds, make when 4 seconds or below to call your main activity.
Upvotes: 0