Saturday, December 24, 2016

Android Tutorial Create Simple Splash Screen Using Thread

Hi! Today i going to share about Splash Screen. Yeah how to display splash screen using Thread. It not to difficult if you understand about Thread.

What is actually Thread means?

A thread is an execution context, which is all the information a CPU needs to execute a stream of instructions.


Suppose you're reading a book, and you want to take a break right now, but you want to be able to come back and resume reading from the exact point where you stopped. One way to achieve that is by jotting down the page number, line number, and word number. So your execution context for reading a book is these 3 numbers.

More, you can read HERE

Back to the main topic, to create a splash screen by follow this tutorial, so the things that you have to do is like the following preparation :

  1. Image, if you don't have an image, you find find much on Google Image
  2. activity_main.xml
  3. MainActivity.java
See also :  How to change language on apps without open menu setting. You can read more HERE

Modify your activity_main.xml, and paste the following code :


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_splash_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/paper"
tools:context="com.putuguna.changelanguagewithoutopensetting.SplashScreenActivity">
<ProgressBar
android:id="@+id/progressbar"
android:layout_marginBottom="50dp"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
change android:background="@drawable/paper" with your image. And don't forget set the progressbar GONE.

Modify your MainActivity.java, please take a look of some code below :

A normal splash page is need a full screen. It means the action bar or something like that must be hidden. The following code will make the screen is full

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_splash_screen);
getSupportActionBar().hide();


Before enter to the thread, in your onCreate set the progressBar is VISIBLE. And after two second, the progressbar will GONE and the activity will move to the next activity. Take a look at the following code :

Handler handler = new Handler();
handler.postDelayed(new Runnable(){
    @Override    public void run(){
        progressBar.setVisibility(View.GONE);
        Intent intent  = new Intent(SplashScreenActivity.this, BeforeMainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);;
        finish();
    }
}, SPLASH_DELAY);

That'ss all about how to create splash screen using Thread. Hope it helps. Thank you

Related Posts


EmoticonEmoticon

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:o
:>)
(o)
:p
:-?
(p)
:-s
8-)
:-t
:-b
b-(
(y)
x-)
(h)