Android:无论我做什么,SplashScreen 都会不断加载
让我们试着让它变得容易理解。
举个例子,我得到了“Page1”和“Page2”和“Page3”。 好的。我在“Page2”上创建了一个启动屏幕,以便用户可以在特定时间(5 秒)内看到“Page2”。它会自动将他定向到“Page3”,我还在“Page2”上添加了两个按钮,以便用户可以单击“Button1”更快地转到“Page3”。或转到“第 1 页”的“Button2” 好吧,我做的一切都是正确的。 但是,如果“Page2”打开并且用户没有触摸任何东西,他就会转到“Page3”..我的问题是用户可以触摸任何“Button1”或“Button2”,它会将他引导到“Page3”,如果他触摸“Button2”并转到“Page1”(在“Page2”上的闪屏时间限制结束后,它会自动将他从“Page1”定向到“Page3”,
请帮助。
我的代码是
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.content.Intent;
import android.view.View.OnClickListener;
import android.widget.Button;
public class StartGame extends Activity {
// ===========================================================
// Fields
// ===========================================================
private final int SPLASH_DISPLAY_LENGHT = 3000;
// ===========================================================
// "Constructors"
// ===========================================================
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.startgame);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(StartGame.this,Fail.class);
StartGame.this.startActivity(mainIntent);
StartGame.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
请帮助,谢谢。 Wahid
编辑:
抱歉我是初学者,我真的不知道如何创建变量, 如果您可以与我分享您的一些知识并向我展示源代码,请这样做。
如果变量意味着按钮,那已经在那里了,但我没有
Let's try to make it easy to understand.
For an Example I got "Page1" and "Page2" And "Page3".
OK. I created a splash screen on "Page2", so the user can see "Page2" for a specific time (5seconds). and it auto directs him to "Page3" and I also added two buttons on "Page2" so the user can either click "Button1" that goes to "Page3" quicker. or "Button2" that goes to "Page 1"
Ok i done that all correct.
But if "Page2" is on and the user doesnt touch anything it takes him to "Page3".. my problem is that the user can touch anything "Button1" or "Button2" it directs him to "Page3", and if he touches "Button2" and goes to "Page1" (after the timelimit of splashscreen on "Page2" is up, it auto directs him from "Page1" to "Page3"
Please Help.
My Code Is
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.content.Intent;
import android.view.View.OnClickListener;
import android.widget.Button;
public class StartGame extends Activity {
// ===========================================================
// Fields
// ===========================================================
private final int SPLASH_DISPLAY_LENGHT = 3000;
// ===========================================================
// "Constructors"
// ===========================================================
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.startgame);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(StartGame.this,Fail.class);
StartGame.this.startActivity(mainIntent);
StartGame.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
Please Help, Thanks.
Wahid
EDIT:
sorry I'm a beginner and I really don't know how to create variables,
Please if you can share some of your knowledge with me and show me an source code.
If variables mean buttons., that's already in there but i didn't
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的活动 2 已通过单击按钮停止,您需要取消 postDelayed 调用。
因此,首先您需要从可运行对象和处理程序创建变量。
然后按下任一按钮,您就可以调用 : ,
如果不再需要触发,这将阻止它触发。
编辑以适合 OP 的初学者配置文件:
You need to cancel the postDelayed call if your activity 2 has been stopped by the click of a button.
So first you need to create variables from your runnable and your handler.
and then on the press of either button you'll be able to call :
Which will stop it from triggering if it is not suppose to anymore.
Edit to suit the beginner profile of the OP :