这是我的SplashActivity课程。 在我的Android应用中,我使用了启动画面。但是当闪屏消失时,在切换到主要活动之前,下一个屏幕变黑。那么,我该如何防止黑屏?
public class SplashScreen extends Activity {
RegisterGCM registerGCM;
private GpsTracker1 mGps;
boolean canLocate;
public static boolean appVisible = false;
public static String lat;
public static String lon;
public static String addr;
public static String addr1;
public static String city;
public static String state;
public static String pin;
public static String country;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
this.mGps = new GpsTracker1(this);
canLocate = mGps.canGetLocation();
if (!canLocate)
{
this.mGps.showSettingsAlert();
}
else
{
getGpsInfo();
}
}
public void getGpsInfo()
{
registerGCM = new RegisterGCM(getApplicationContext());
String regId = registerGCM.getRegistrationId();
if (TextUtils.isEmpty(regId))
{
registerGCM.registerGCM();
}
lat = this.mGps.getLatitude();
lon = this.mGps.getLongitude();
addr = this.mGps.getAddress();
addr1 = this.mGps.getAddress1();
city = this.mGps.getCity();
state = this.mGps.getState();
pin = this.mGps.getPostalcode();
country = this.mGps.getCountry();
Thread timerThread = new Thread()
{
public void run()
{
try
{
sleep(2000);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
finally
{
Intent intent = new Intent(SplashScreen.this, Category_Activity.class);
startActivity(intent);
finish();
}
}
};
timerThread.start();
}
@Override
public void onStart()
{
super.onStart();
}
public void onStop()
{
super.onStop();
}
public void onResume()
{
super.onResume();
appVisible = true;
}
public void onPause()
{
super.onPause();
appVisible = false;
}
}
答案 0 :(得分:0)
为什么不发布runnable而不是阻止线程?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashScreen.this, Category_Activity.class);
startActivity(intent);
finish();
}
}, 2000);
// Other details
}
它在主线程中开始您的活动。