https://github.com/hellofaizan/splashscreen
https://github.com/hellofaizan/splashscreen
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/hellofaizan/splashscreen
- Owner: hellofaizan
- Created: 2021-10-14T08:32:28.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-12T04:26:34.000Z (over 4 years ago)
- Last Synced: 2024-10-12T11:11:55.638Z (over 1 year ago)
- Language: Java
- Size: 114 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SplashScreen Concept by Curious Faizan
# How to use a Splash screen correctly
Well, there are a lot of blog tutorials teaching how to create a splash screen like this:
```java
public class SplashActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
...
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
}, 3000); // But it gives fuc**ng white or black screen on App Open before this activity
}
}
```
The thing is, this is nothing but a 3 seconds waisting of the user's time! But it gives fuc**ng white or black screen on App Open before this activity
##### As you can notice, Google has gotten their opinion in favor of Splash Screens on their [Official Material Design Documentation](https://material.io/guidelines/patterns/launch-screens.html)
###### But, is this something you just put anyway on your app to make the user waste his time?
##### No. And Google advocated against splash screens like this, and even called it an anti-pattern [on this video](https://www.youtube.com/watch?v=pEGWcMTxs3I&feature=youtu.be&t=1434).
##### So, is there a way to make use of this pattern on the right way? The answer is, Yes!
## So, how could one do to create a Splash Screen just for the amount of time the App needs to open the Main Activity?
##### Well, actually, it's easy. The ingredients are:
* An Activity for the Splash Screen (without the layout file)
* Your Manifest: to declare you Splash Screen as the Launcher
* One drawable file to customize the splash screen a little
*The splash view has to be ready immediately, even before you can inflate a layout file in your splash activity.*
## The recipe:
###### Create your Splash Screen Activity without layout file
```java
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** START - this is the purpose of this Activity */
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
/** END - everything more than this is time consuming */
}
}
```
###### Create a drawable file
**splash_bg.xml
```xml
```
###### and your Manifest should look something like this
```xml
```
###### we've set a different Theme for the SplashActivity, so we can call our drawable resource on it
```xml
<item name="android:windowBackground">@drawable/splash_bg</item>
```
That is it. You can clone the project using Android Studio and take a look.