Reputation: 9
So, when I compile the code for my splash screen and run it, it only shows a blank screen. The layout editor perfectly renders the screen. I recently switched to Kotlin, so maybe I did some mistake in the code.
package com.superstar.scrolls2
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
class LauncherActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
setContentView(R.layout.launcher_layout)
Handler().postDelayed({
var i : Intent=Intent(this@LauncherActivity, LoginActivity::class.java)
startActivity(i)
}, 5000)
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.superstar.scrolls2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Scrolls2" >
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
<activity android:name=".LauncherActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".LoginActivity"/>
</application>
</manifest>
and the layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@drawable/parchment_chinese"
android:id="@+id/linearLayout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="124dp"
android:background="#00FFFFFF"
android:src="@drawable/scroll_one_coloured"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499"
tools:layout_conversion_absoluteHeight="124dp"
tools:layout_conversion_absoluteWidth="163dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="144dp"
android:fontFamily="@font/medievalsharp"
android:text="Scrolls"
android:textColor="#9A5712"
android:textSize="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.511"
app:layout_constraintStart_toStartOf="parent"
tools:layout_conversion_absoluteHeight="59dp"
tools:layout_conversion_absoluteWidth="157dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
So, the splash screen is completely black with the toolbar at the top showing the app name. Just to test, I wrote the same screen with java which works all good. The app doesn't crash or anything. And just for testing purposes, I didn't finish() launcher activity to know if it actually starts the LoginActivity, but it doesn't since there's only one activity in the stack.
Upvotes: 0
Views: 1164
Reputation: 12953
The problem is you are overriding the wrong onCreate()
,it will never be called and you content won't be set
use
override fun onCreate(savedInstanceState: Bundle?)
instead of
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?)
Upvotes: 3