我的问题是,如果我通过在清单中添加此行将我的启动设置为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;
}
}
答案 0 :(得分:1)
您可以在启动画面活动中执行所有后台工作,然后启动主要活动,而不是使用启动作为对话。如果您需要对话动画,则可以使用此类动画。
overridePendingTransition(R.anim.come_up,R.anim.go_down);
通过这种方式,您可以管理活动切换时间。
答案 1 :(得分: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");
}
答案 2 :(得分: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();
答案 3 :(得分:0)
这是闪屏显示的代码,有一些时间延迟 .. 这里在splash_screen.xml中的drawable中设置了splash image。
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);
}
}
答案 4 :(得分:0)
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(SplashActivity.this, MainActivity.class);
startActivity(i);
finish();
}
}, DURATION);
}