我的启动画面显示在genymotion中,但在真正的Android设备上,屏幕只有白色5秒钟。
布局是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/launchphone"
android:scaleType="fitXY"/>
</RelativeLayout>
活动代码:
public class MainActivity extends Activity {
private DownloadAPITask task;
private String response;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getResources().getConfiguration().isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE)){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}else{
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
setContentView(R.layout.activity_main);
task = new DownloadAPITask(this, null, new Runnable(){
@Override
public void run(){
onAPIDownload();
}
});
task.execute(new APIRequest("http://my-site.com/api/", "request=asd"));
}
private void onAPIDownload(){
StringBuilder strb = task.getResponse();
if(strb == null){
response = null;
}else{
response = strb.toString();
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
launch();
}
}, 2000);
}
private void launch(){
Intent intent = new Intent(this, StartActivity.class);
intent.putExtra(StartActivity.API, response);
startActivity(intent);
finish();
}
}
drawable / launchphone是一个.png文件,位于res / drawable /不在任何dpi依赖的可绘制位置,因为它只是全屏缩放。我假设在一个真实的设备上漫长的启动时间,它是启动画面,但不是渲染这个图像,它只是显示白色。
非常感谢任何帮助。
答案 0 :(得分:0)
您必须:import android.os.Handler;
new Handler().postDelayed(new Runnable){
@Override
public void run() {
Intent intent = new Intent(getApplicationContext(), NextActivity.class);
startActivity(intent);
ThisActivity.this.finish();
},1000);
}
您可以在启动画面的任何持续时间内写入。 (在这种情况下,时间= 1000毫秒)