I have a splash screen which has a progressbar where in the future I will perform the bd existence checks of the application etc. But now I would like to understand how to make that bar progress for example through a for loop.
How would the code that should add to the current so that instead of waiting 3000ms to move from the splash screen to the main activity. You have to fill in the progressbar at that time by means of a loop
JAVA:
public class SplashScreenActivity extends Activity {
// Set the duration of the splash screen
private static final long SPLASH_SCREEN_DELAY = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set portrait orientation
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.splash_screen);
TimerTask task = new TimerTask() {
@Override
public void run() {
// Start the next activity
Intent mainIntent = new Intent().setClass(SplashScreenActivity.this, MainActivity.class);
startActivity(mainIntent);
// Close the activity so the user won't able to go back this
// activity pressing Back button
finish();
}
};
// Simulate a long loading process on application startup.
Timer timer = new Timer();
timer.schedule(task, SPLASH_SCREEN_DELAY);
}
}
XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/splash_screenImView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/app_name"
android:scaleType="fitXY"
android:src="@drawable/splash_screen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<ProgressBar
android:id="@+id/splash_screenProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginBottom="?attr/actionBarSize"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>