1

This is for a splash screen. I've followed the tutorial but it's still not working. It keeps on getting an error.

This is my code:

package id.ac.umn.finalproject;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class MainActivity extends AppCompatActivity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 Intent startApp = new Intent(MainActivity.this, PemasukanActivity.class);
 new Handler().postDelayed(startActivity(startApp), 3000);
 }
}
Nimantha
6,5466 gold badges32 silver badges78 bronze badges
asked Nov 18, 2021 at 2:43

2 Answers 2

0

The correct way to create a Splash screen is as follows

style.xml

 <style name="SplashStyle" parent="Theme.MaterialComponents.DayNight.NoActionBar">
 <item name="android:windowBackground">@drawable/splash</item>
 </style>

Splash.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:drawable="@color/black" /> // background color
 <item
 android:drawable="@drawable/ic_launcher" /> // logo
 android:gravity="center" />
</layer-list>

Manifest

<activity
 android:name=".SplashActivity"
 android:exported="true"
 android:noHistory="true"
 android:theme="@style/SplashStyle">
 <intent-filter>
 <action android:name="android.intent.action.MAIN" />
 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 </activity>

SplashActivity.java

public class SplashActivity extends AppCompatActivity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_splash); // No need setContentView
 
 Intent intent = new Intent(SplashActivity.this,MainActivity.class);
 startActivity(intent);
 }
answered Nov 18, 2021 at 4:08
Sign up to request clarification or add additional context in comments.

Comments

0

In Kotlin try this:

Handler(Looper.getMainLooper()).postDelayed({
 Intent startApp = new Intent(MainActivity.this, PemasukanActivity.class);
 startActivity(startApp)
 }, 3000)
Nimantha
6,5466 gold badges32 silver badges78 bronze badges
answered Nov 18, 2021 at 3:02

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.