gpt4 book ai didi

java - 应用程序需要 13 秒才能显示启动屏幕

转载 作者:行者123 更新时间:2023-12-01 09:58:54 24 4
gpt4 key购买 nike

我的启动画面

/**
* Created by HumzaYunas on 05/01/2016.
*/
import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class splashscreen extends Activity {
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
/** Called when the activity is first created. */
Thread splashTread;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen);
StartAnimations();
}
private void StartAnimations() {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
anim.reset();
LinearLayout l=(LinearLayout) findViewById(R.id.lin_lay);
l.clearAnimation();
l.startAnimation(anim);

anim = AnimationUtils.loadAnimation(this, R.anim.translate);
anim.reset();
ImageView iv = (ImageView) findViewById(R.id.splash);
iv.clearAnimation();
iv.startAnimation(anim);

splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
// Splash screen pause time
while (waited < 5000) {
sleep(100);
waited += 100;
}
Intent intent = new Intent(splashscreen.this,
MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
splashscreen.this.finish();
} catch (InterruptedException e) {
// do nothing
} finally {
splashscreen.this.finish();
}

}
};
splashTread.start();

}

}

据我所知,这花费了很多时间:(……我只是好奇如何加载像 facebook 这样的应用程序,当我们点击 fb 图标时,应用程序加载速度非常快并且会启动显示了屏幕,但在我的应用程序中我遇到了这个问题。任何帮助将不胜感激:) ..

这里是我的 androidmanifest

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".splashscreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
</activity>
<activity
android:name=".ShowPosts"
android:label="@string/posttitle"
android:parentActivityName=".MainActivity"/>
<activity android:name=".LiveScores" />
</application>

我刚刚将启动屏幕作为主要 Activity ,因为我想快速加载我的应用程序,以便启动屏幕需要时间,然后我的主要 Activity 有一些时间来工作和加载

最佳答案

您可以在这里阅读更多内容: Add splash in application

如果您还想在屏幕之间创建动画,请参阅 Activity 之间的转换:

transitions between activities

关于java - 应用程序需要 13 秒才能显示启动屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36964289/

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