1

我的问题是,如果我通过在清单中添加这一行将我的启动设置为 a Dialog,则会有延迟:android:theme="@android:style/Theme.Holo.Dialog.NoActionBar"

启动屏幕消失后,主要活动大约需要 6 秒或更长时间才会出现。

我怎样才能让这种延迟消失?

启动代码:

public class SplashActivity extends Activity {
private final int DURATION = 3000;
private Thread mSplashThread;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    mSplashThread = new Thread() {

        @Override
        public void run() {
            synchronized (this) {
                try {
                    wait(DURATION);
                } catch (InterruptedException e) {
                } finally {
                    finish();
                    Intent intent = new Intent(getBaseContext(),
                            MainActivity.class);
                    startActivity(intent);
                }
            }
        }

    };
mSplashThread.start();

}

    @Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        synchronized (mSplashThread) {
            mSplashThread.notify();
        }
    }
    return true;
}

}

4

5 回答 5

1

您可以在启动画面活动中完成所有后台工作,然后开始您的主要活动,而不是使用启动画面作为对话。如果您需要对话动画,那么您可以使用这样的动画。

overridePendingTransition(R.anim.come_up, R.anim.go_down);

通过这个,您可以管理您的活动切换时间。

于 2013-07-22T09:53:22.130 回答
0

这对我来说是最好的..

final int splashTimeOut = 3000;

    Thread splashThread = new Thread(){
                int wait = 0;
                @Override
                public void run() {
                    try {
                        super.run();
                        while(wait < splashTimeOut){
                            sleep(100);
                            wait += 100;
                        }
                    } catch (Exception e) {
                    }finally{
    startActivity(new Intent(SplashScreen.this,LoginActivity.class));
                        finish();
                    }
                }
            };
            splashThread.start();
于 2013-07-22T10:09:51.353 回答
0

这是带有一些时间延迟的启动画面显示的代码。这里在 splash_screen.xml 中的 drawable 中设置启动图像。

 import android.location.Criteria;
 import android.location.Location;
 import android.location.LocationListener;
 import android.location.LocationManager;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.telephony.TelephonyManager;
 import android.util.Log;
 import android.view.Window;
 import android.widget.Toast;
 import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;

public class SplashScreen extends Activity  {

LocationManager locationManager;
String provider, formattedDate, imeid;
double lat, lon;



@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.splash_screen);

    Calendar c = Calendar.getInstance();
     SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        formattedDate = df.format(c.getTime());



    new Handler().postDelayed(new Runnable() {
        public void run() {
            Log.i("JO", "run");
            Intent in = new Intent(SplashScreen.this,SecondActivity.class);
            //in.putExtra("refreshclick", clickRefreshButton);
            //in.putExtra("Current_Date", formattedDate);
        //  in.putExtra("ImeiId", imeid);
//Log.i("JO", "Current_Date"+formattedDate+";
     ImeiId"+imeid+";lat"+lat+"lon"+lon);
            startActivity(in);

            finish();
        }
    }, 1000);

}



    }
于 2013-07-22T10:25:12.157 回答
0

我不确定这个答案是否合适,但我已经这样做了:

    @Override
    public void run() 
    {
        // TODO Auto-generated method stub
        startActivity( new Intent ( SplashActivity.this , MainActivity.class ) ) ;
    }

    @Override
    protected void onStart() 
    {
        super.onStart();
        if(!isClosed)
            splashHandler.postDelayed(this, "putYourTimeHere");
    }
于 2013-07-22T09:55:51.900 回答
0
new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {

                Intent i = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(i);

                finish();
            }
        }, DURATION);
    }
于 2018-01-31T12:36:05.770 回答