现在是我的项目情况。
考虑一下,看来没有问题。
但是在应用启动之后
在MainActivity
通话之前,SplashActivity
屏幕会短暂可见。
令人惊讶的是,我没有在其他设备上看到它,只有银河s8。
当然,我知道这不是一般结构。但是我无法理解,因为我一直在正常工作。 白色是冷启动样式和splashActivity。 红色是mainActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// some getIntent code
startActivityForResult(new Intent(this, SplashActivity.class), RESULTCODE_);
setInitLayout();
}
清单
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SplashActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme" >
</activity>
minSdkVersion 21
targetSdkVersion 28
答案 0 :(得分:1)
如果您将样式与 android:windowBackground
一起用于启动活动,请不要调用 setContentView()
。仅此而已!
答案 1 :(得分:0)
您已将MainActivity类作为清单中的启动器活动。我假设您的启动画面活动称为SplashActivity。如果您希望它先显示为SplashScreen,然后再显示MainActivity,则将清单代码更改为:
<activity android:name=".SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme" >
</activity>
<activity android:name=".IntroActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme" >
</activity>
然后按照Ismail的建议在he has provided
链接中创建您的SplashActivity。答案 2 :(得分:0)
以这种方式使用启动画面不是一个好主意。应当严格避免。
使用这种方法,您还可以导致启动启动期间出现空白白页的问题,而这正是您发生的事情!
我建议您阅读this文章,并尝试以正确的方式制作您的启动画面,以避免此类行为!
答案 3 :(得分:0)
使用此线程代码进行启动活动将更好地工作-
公共类SplashActivity扩展了AppCompatActivity {
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread thread = new Thread() {
public void run(){
try{
sleep(3000);
}catch (InterruptedException e){
e.printStackTrace();
}finally {
Intent mainAct=new Intent(SplashActivity.this, MainActivity.class);
startActivity(mainAct);
finish();
}
}
};
thread.start();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
答案 4 :(得分:0)
Use this thread code for splash activity it will better work -
public class SplashActivity extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread thread = new Thread() {
public void run(){
try{
sleep(3000);
}catch (InterruptedException e){
e.printStackTrace();
}finally {
Intent mainAct=new Intent(SplashActivity.this, MainActivity.class);
startActivity(mainAct);
finish();
}
}
};
thread.start();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
and your manifest class will be look like this :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.diskapp">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name=".Activities.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activities.MainActivity" />
</application>
</manifest>
答案 5 :(得分:0)
仅在有限的时间内添加处理程序并完成当前活动
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//actvity transaction
}
},3000);