闪屏问题
我正在使用以下代码创建启动屏幕,当我按后退键时,应用程序将移动到主屏幕,并在几秒钟内显示我的下一个主菜单屏幕。我在 onBackPressed() 中调用 finish(),我想关闭应用程序在启动屏幕中按后退键。任何人都可以帮助我吗?
谢谢!!
Thread splashThread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while (_active && (waited < 2000)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch (InterruptedException e) {
// do nothing
} finally {
finish();
startActivity(new Intent("next activity"));
stop();
}
}
};
splashThread.start();
I am creating a splash screen using the following code ,when i press back key the application moves to the home screen and within a few seconds shows my next mainmenu screen.I am calling finish() in onBackPressed(),I want to close the app on pressing back key in the splash screen.can any one help me on this??
Thanks!!
Thread splashThread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while (_active && (waited < 2000)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch (InterruptedException e) {
// do nothing
} finally {
finish();
startActivity(new Intent("next activity"));
stop();
}
}
};
splashThread.start();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是因为您在
startActivity(new Intent("next Activity"));
之前调用finish();
将
finish();
与 <代码>startActivity(new Intent("下一个活动"));It's because you call
finish();
before thestartActivity(new Intent("next activity"));
Swap
finish();
withstartActivity(new Intent("next activity"));
它正在我的应用程序中运行
}
It is working in my application
}
该解决方案仅解决后退按钮的问题。如果用户按下主页按钮,不良行为仍然会发生。重写 onStop 方法并在那里做你的事情不是更容易吗?
this solution only solves the problem for the back-button. If users press the home-button the unwanted behavior will still occur. Wouldn't it be easier to overwrite the onStop method and do your thing in there?
尝试使用这个:
其中 SplashScreen 是活动的名称。
Try using this:
where SplashScreen is the name of the Activity.
AndriodManifest.xml
AndriodManifest.xml