Android 自动将停止活动带到前面
我有一个android应用程序。在那有飞溅和主屏幕。当我按下Splash page时,应用程序将进入后台,但一段时间后,它会自动进入主页的前端。我怎样才能解决这个问题 飞溅Android 自动将停止活动带到前面,android,android-activity,Android,Android Activity,我有一个android应用程序。在那有飞溅和主屏幕。当我按下Splash page时,应用程序将进入后台,但一段时间后,它会自动进入主页的前端。我怎样才能解决这个问题 飞溅 Intent in = new Intent(SplashActivity.this, HomeActivity.class); startActivity(in); overridePendingTransition(R.anim.slide_in_from_bo
Intent in = new Intent(SplashActivity.this,
HomeActivity.class);
startActivity(in);
overridePendingTransition(R.anim.slide_in_from_bottom, R.anim.slide_out_to_top);
finish();
您可以使用如下标志:
Intent intent = new Intent(SplashActivity.this, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
new Timer().schedule(new TimerTask(){
public void run() {
SplashActivity.this.runOnUiThread(new Runnable() {
public void run() {
Intent intent = new Intent(SplashActivity.this,HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
}
}, 2000);
Intent.FLAG\u ACTIVITY\u CLEAR\u TOP清除活动堆栈
如果你想在一段时间后开始一项活动,你可以这样做:
Intent intent = new Intent(SplashActivity.this, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
new Timer().schedule(new TimerTask(){
public void run() {
SplashActivity.this.runOnUiThread(new Runnable() {
public void run() {
Intent intent = new Intent(SplashActivity.this,HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
}
}, 2000);
我认为您希望在splashScreen上几秒钟后自动打开homeActivity。您可以为此使用处理程序,以下是代码:
private static int SPLASH_TIME_OUT = 1500; // change the time according to your need
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
@Override
public void run() {
// This method will be executed once the timer is over
//open Activity when internet is connected
Intent intent = new Intent(Splash Activity.this, HomeActivity.class);
startActivity(intent);
finish();
}
}, SPLASH_TIME_OUT);
要防止出现这种情况,您需要在启动MainActivity之前确定SplashActivity是否已暂停。我假设您的SplashActivity在启动MainActivity之前正在进行一些处理。如果在开始MainActivity之前调用了onPause,您应该可以通过在onPause中调用finish来防止这种情况。您能否进一步解释一下您所面临的问题,按启动页时,应用程序如何进入后台?您已经完成了。它无法执行您所说的操作。我必须是您代码的另一部分来执行此操作。@Kaveri,而应用程序正在使用启动页运行。如果我按下主页并打开另一个应用程序,那么这一次就结束了。此时,应用程序会自动在主页上显示在最前面。这意味着会覆盖我打开的另一个应用程序。这是在处理程序或任何其他处理程序中写入的意图的代码。?在新处理程序中。postDelayedi不想在一段时间后显示活动。场景是应用程序正在使用启动页运行。如果我按下主页并打开另一个应用程序,那么这一次就结束了。这一次,该应用程序将自动与主页一起放在最前面。这意味着该应用程序将覆盖我打开的另一个应用程序。如果按home(主页)按钮,我不想将应用放在前面。是否希望在恢复应用程序时再次加载启动页?我不想在一段时间后显示活动。场景是应用程序正在使用启动页运行。如果我按下主页并打开另一个应用程序,那么这一次就结束了。这一次,该应用程序将自动与主页一起放在最前面。这意味着该应用程序将覆盖我打开的另一个应用程序。我不想把应用程序放在前面,如果我按下主页按钮