Android预加载活动 [英] Android pre`loading Activity

查看:450
本文介绍了Android预加载活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我的应用程序中第一个活动的加载有疑问.在加载之前,应用会显示以下屏幕: https://www.dropbox.com/s/r33n3u3xfmth345/Screenshot_2013-08-16-12-02-08.png ,而我想直接加载我的Activity.

I have a question regarding the loading of the first Activity in my App. Before loading it, app shows this screen: https://www.dropbox.com/s/r33n3u3xfmth345/Screenshot_2013-08-16-12-02-08.png , and what I would like, is to load directly my Activity.

我将在屏幕上提及我m using SherlockActivity, and I already tried setting the Theme both in Manifest or programatically in onCreate() of my Activity, with same result (pre-load 2-3秒钟,然后加载我的活动). 有什么想法吗?

I'll mention that Im using SherlockActivity, and I already tried setting the Theme both in Manifest or programatically in onCreate() of my Activity, with same result (pre-loads with that screen for 2-3 secs, then loads my Activity). Any thoughts ?

推荐答案

您必须使用启动画面活动,然后您必须从以下位置开始自己的活动闪屏活动.

You have to use the splash screen Activity and after that you have to start your own activity from that Splash screen Activity.

这是 splashActivity的代码.

public class SplashActivity extends Activity {
private int splashTime = 3000;
private Thread thread;
private ProgressBar mSpinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_splash);
    mSpinner = (ProgressBar) findViewById(R.id.Splash_ProgressBar);
    mSpinner.setIndeterminate(true);
    thread = new Thread(runable);
    thread.start(); 
}
public Runnable runable = new Runnable() {
    public void run() {
        try {
            Thread.sleep(splashTime);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        try {
            startActivity(new Intent(SplashActivity.this,YourActivityName.class));
            finish();
        } catch (Exception e) {
            // TODO: handle exception
        }
    }
};
}

这是 activity_spalsh.xml 文件的代码.....

Here is code for activity_spalsh.xml file .....

<?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="#48AD83"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_marginBottom="20dp"
    android:layout_marginTop="10dp"
    android:gravity="center_horizontal"
    android:text="  your app name "
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#A52A2A" />

<ProgressBar
    android:id="@+id/Splash_ProgressBar"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerInParent="true"
    android:layout_marginTop="5dp" />

</RelativeLayout>

这篇关于Android预加载活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆