Android 启动屏幕显示为空白屏幕
我做了一个启动布局,它持续一段时间,然后其他活动应该被加载,单独它就可以完美地工作,但当它连接到其他活动时,它会显示空白屏幕Android 启动屏幕显示为空白屏幕,android,splash-screen,Android,Splash Screen,我做了一个启动布局,它持续一段时间,然后其他活动应该被加载,单独它就可以完美地工作,但当它连接到其他活动时,它会显示空白屏幕 mainifest文件: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="andy.propaganda" android:installLocation
mainifest
文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="andy.propaganda"
android:installLocation="auto" >
<application
android:allowBackup="true"
android:icon="@drawable/my_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar"
>
<activity
android:name=".shit"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="com.coderefer.androidsplashscreenexample.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Splash"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
main
活动:
package andy.propaganda;
import android.app.Activity;
import android.os.Bundle;
/**
* Created by Andrew on 2/5/2016.
*/
public class shit extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
splash.xml
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@color/MyBlue"
>
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:src="@drawable/my_launcher"
android:paddingTop="60dp"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:src="@drawable/loading"
android:layout_marginBottom="43dp"
android:id="@+id/loading_view"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="loading your files"
android:id="@+id/welcome_message"
android:focusable="false"
android:textColor="#010101"
android:textSize="@dimen/abc_action_bar_progress_bar_size"
android:layout_above="@+id/loading_view"
android:layout_alignRight="@+id/imageView"
android:layout_alignEnd="@+id/imageView"
android:layout_marginBottom="50dp" />
</RelativeLayout>
对于(int i=0;i<100000000;i++),您应该在启动屏幕上使用计时器,而不是
代码>将等待一段时间(假设5秒),然后加载另一个活动
package andy.propaganda;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
/**
* Created by Andrew on 2/4/2016.
*/
public class Splash extends Activity {
//welcome animation
ImageView loading_img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
loading_img = (ImageView)findViewById(R.id.loading_view);
final Animation animatable = AnimationUtils.loadAnimation(this, R.anim.welcome_screen_anim);
loading_img.setAnimation(animatable);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// your task
Intent intent = new Intent(this, shit.class);
intent.putExtra("jhjh", 8);
startActivity(intent);
}
}, 5000);
}
}
对于(inti=0;i<100000000;i++),应该在启动屏幕上使用计时器,而不是代码>将等待一段时间(假设5秒),然后加载另一个活动
package andy.propaganda;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
/**
* Created by Andrew on 2/4/2016.
*/
public class Splash extends Activity {
//welcome animation
ImageView loading_img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
loading_img = (ImageView)findViewById(R.id.loading_view);
final Animation animatable = AnimationUtils.loadAnimation(this, R.anim.welcome_screen_anim);
loading_img.setAnimation(animatable);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// your task
Intent intent = new Intent(this, shit.class);
intent.putExtra("jhjh", 8);
startActivity(intent);
}
}, 5000);
}
}
首先,不要将for循环用于等待时间,而应使用处理程序进行如下操作:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(Splash.this, shit.class));
finish();
}
}, 500);
然后从manifest.xml中删除此行:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
链接详细解释了启动屏幕
首先,不要使用for循环等待时间,而不是使用处理程序,如下所示:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(Splash.this, shit.class));
finish();
}
}, 500);
然后从manifest.xml中删除此行:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
详细解释了启动屏幕的链接
RxJava解决方案:
Observable.empty().subscribeOn(AndroidSchadelurs.mainThread()).delay(500, TimeUtils.MILISECONDS).subscribe(this::startActivity(this, new Intent));
RxJava解决方案:
Observable.empty().subscribeOn(AndroidSchadelurs.mainThread()).delay(500, TimeUtils.MILISECONDS).subscribe(this::startActivity(this, new Intent));
从你的狗屎清单活动中删除这一行我试过了,但没有区别Move for loop和use Handler你的代码似乎没问题:)从你的狗屎清单活动中删除这一行我试过了,但是没有区别Move for loop和use Handler,您的代码似乎没有问题:)它工作得很好,但是如果我需要执行特定任务并将其作为参数发送到下一个活动,我想搜索整个设备以加载数组中的所有mps文件并将其发送到下一个活动呢?计划(TimerTask任务,长延迟)方法用于计划在指定延迟后开始执行指定的任务。您可以在run方法中定义任务。它工作得很好,但如果我需要执行特定任务并将其作为参数发送到下一个活动,我希望搜索整个设备以加载数组中的所有mps文件,该怎么办d是否将其发送到下一个活动?schedule(TimerTask task,long delay,)方法用于计划在指定延迟后开始执行指定任务。您可以在run方法中定义任务。