感谢阅读并抱歉我的英语。 我的问题是我的Android应用程序应该显示带有imageview和textview的布局。它没有显示图像和文本的内容,它开始运行该活动的代码并启动下一个活动而不显示它。
¿如何在运行其余代码之前强制显示它?
感谢您的回复。
我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lay_inicio);
//Inicio de la actividad:
//1-Obtiene la IP del PC
Intent i;
String IP = getIP();
if(IP == null){//Si no se ha obtenido la IP se pregunta si se desea salir o reintentarlo
i = new Intent(this,ReintentarSalir.class);
startActivity(i);
}
else{
//2-Envia su IP al PC
sendIP(IP);
//3-Se pasa a la actividad en la que se pregunta si se desea enviar o recibir datos
i = new Intent(this,EnviarRecibir.class);
i.putExtra("IP", IP);
startActivity(i);
finish();
}
finish();
}
我希望在调用函数getIP()
之前显示“lay_inicio”布局答案 0 :(得分:0)
如果您想要像启动画面一样的东西,那么请进行启动画面活动。使用线程显示它一段时间,然后启动另一个活动。像这样:
public class SplashScreen extends Activity {
/**
* The thread to process splash screen events
*/
private Thread mSplashThread;
private final static int SPLASH_SCREEN_TIME = 1500;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Splash screen view
setContentView(R.layout.splash);
final SplashScreen sPlashScreen = this;
// The thread to wait for splash screen events
mSplashThread = new Thread(){
@Override
public void run(){
try {
synchronized(this){
// Wait given period of time or exit on touch
wait(SPLASH_SCREEN_TIME);
}
}
catch(InterruptedException ex){
}
// Run next activity
Intent intent = new Intent();
intent.setClass(sPlashScreen, HomeScreenActivity.class);
intent.putExtra("showTheme", true);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
};
mSplashThread.start();
}
/**
* Processes splash screen touch events
*/
@Override
public boolean onTouchEvent(MotionEvent evt)
{
if(evt.getAction() == MotionEvent.ACTION_DOWN)
{
synchronized(mSplashThread){
mSplashThread.notifyAll();
}
}
return true;
}
}