首页 > 解决方案 > 飞溅后未显示主要活动

问题描述

这是我的代码。启动屏幕后主要活动不会运行,并且没有出现错误。它是一个带有导航抽屉的选项卡式活动。可能是什么问题?我试了几次。我在应用程序中尝试了不同的活动以成功运行,但它不适用于主要活动。请帮帮我。

====

闪屏

package com.mohanadmarket.myapplication50

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import java.util.*

class SplashActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)

        Timer().schedule(object : TimerTask(){
            override fun run() {
                val intent= Intent(this@SplashActivity,MainActivity::class.java)
                startActivity(intent)
             finish()
            }

        },5000L)
    }
}

主要节日

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mohanadmarket.myapplication50">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/sudacars_icon"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".SplashActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleInstance" />
    </application>

</manifest>

请告诉我怎么做

谢谢!!

标签: androidkotlin

解决方案


你的代码看起来不错。但另一种解决方案是使用Handler

new Handler().postDelayed(new Runnable() {
      @Override
      public void run() {
         startActivity(new Intent(SplashActivity.this, MainActivity.class));
     }
}, 5000);

推荐阅读