gpt4 book ai didi

java - Android Studio 启动画面在 Activity 开始前消失

转载 作者:行者123 更新时间:2023-12-01 23:24:49 25 4
gpt4 key购买 nike

我遇到了闪屏问题。它仅显示半秒,并在 HomeZastepowy Activity 出现前几秒钟消失。我根据这个网站制作了这个启动画面https://android.jlelse.eu/right-way-to-create-splash-screen-on-android-e7f1709ba154 。我哪里出错了?

主要 Activity 代码:


import android.content.Intent;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;

import java.util.Objects;


public class MainActivity extends AppCompatActivity {
FirebaseAuth mAuth;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();

if (mAuth.getCurrentUser() != null) {
String uid = mAuth.getUid();
final DocumentReference mDocRef = FirebaseFirestore.getInstance().collection("Data").document("userInfo").collection(Objects.requireNonNull(uid)).document(uid);
mDocRef.get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists()) {
String user = documentSnapshot.getString("user");
assert user != null;
if (user.equals("user")) {

Log.d("tag", String.valueOf(mAuth.getUid()));

Intent intent = new Intent(getApplicationContext(),
HomeUsrActivity.class);
startActivity(intent);
finish();
} else {
Log.d("tag", "Zastepowy");

Log.d("tag", String.valueOf(mAuth.getUid()));

startActivity(new Intent(MainActivity.this, HomeZastepowy.class));

finish();

}
}
}


}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, "Error", Toast.LENGTH_SHORT).show();
}
});
finish();


}else {
Intent intent = new Intent(getApplicationContext(),
HomeActivity.class);
startActivity(intent);
finish();
}


}


}

AndroidManifest代码:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zapp4">

<application
android:allowBackup="true"
android:fullBackupContent="@xml/backup_descriptor"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".HomeUsrActivity"></activity>
<activity android:name=".LoginActivity" />
<activity android:name=".punktyog" />
<activity android:name=".punktywz" />
<activity android:name=".HomeZastepowy" />
<activity android:name=".tradycje" />
<activity android:name=".wiedza" />
<activity android:name=".kontakt" />
<activity android:name=".zastepy" />
<activity android:name=".historia" />
<activity android:name=".onas" />
<activity android:name=".HomeActivity" />
<activity android:name=".MainActivity" android:theme="@style/SplashScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>

最佳答案

我认为问题是您忘记从代码中删除这一行:

setContentView(R.layout.activity_main)

因为您设置了ContentView,所以它会覆盖您的主题背景。所以尝试评论这一行并尝试一下。

关于java - Android Studio 启动画面在 Activity 开始前消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58309959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com