Android splashscreen后退
我正在为android应用程序实现一个splashscreen。我只想在应用程序刚启动时显示一次SplashScreen。完成一些工作后,我想继续使用该应用程序。如果用户按下后退按钮,我不希望它返回到splashscreen,我只希望应用程序退出。我如何以最佳方式实现这一点?如何清除第一个活动的后台 当您要进入启动屏幕后的第二个活动时,请调用finish()Android splashscreen后退,android,splash-screen,back-stack,Android,Splash Screen,Back Stack,我正在为android应用程序实现一个splashscreen。我只想在应用程序刚启动时显示一次SplashScreen。完成一些工作后,我想继续使用该应用程序。如果用户按下后退按钮,我不希望它返回到splashscreen,我只希望应用程序退出。我如何以最佳方式实现这一点?如何清除第一个活动的后台 当您要进入启动屏幕后的第二个活动时,请调用finish() 这样,当用户按下返回键时,堆栈中不会有任何活动。在android中使用共享预引用,并第一次存储该值。。从第二次检查是否存在值不显示启动屏幕
这样,当用户按下返回键时,堆栈中不会有任何活动。在android中使用共享预引用,并第一次存储该值。。从第二次检查是否存在值不显示启动屏幕
编辑首选项请遵循,因为您应该使用SharedReferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(!prefs.getBoolean("first_time", false))
{
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("first_time", true);
editor.commit();
Intent i = new Intent(splash.this, otherSplash.class);
this.startActivity(i);
this.finish();
}
else
// Not firsttime Direct it as you wish
}
如果您只想在应用程序启动时第一次显示启动屏幕, 然后您可以使用上述共享首选项的解决方案。 但我想你应该经历以下情况:
android:launchMode=“singleTask”
嗨,试试这段代码,它会帮助你,但它会显示飞溅,每当你打开应用程序
您不清楚具体的行为,因此以下是一些选项: 答:您希望它在每次任务(应用程序)重新启动时显示启动活动,例如在手机重新启动、用户手动关闭任务后,或者当Android出于内存原因将其删除时。(这通常用于品牌或授权徽标。)在这些情况下,从主活动的onCreate()启动启动,然后完成()启动屏幕,以允许用户返回主视图。这样,向后导航将不会使启动活动返回,因为它不再位于导航堆栈中 B:你想让它在安装后第一次启动应用程序时显示初始屏幕,但永远不要再出现。(通常用于“欢迎”或“入门”帮助视图。)使用此处其他答案或文档中所述的SharedReference设置。在它应该显示启动的情况下,我仍然建议使用选项A作为最简单的方法,在第一次启动后第一次关闭启动屏幕后,不再显示启动屏幕
C:一个更复杂、未知的导航系统?了解并可以让它做任何你想做的事情。打开新活动后
this.finish()代码>你应该这样做
Intent intent = new Intent(this, HomeActivity.class);
startActivity(intent);
this.finish ();
但我只想显示一次splashscreen。如果用户关闭应用程序并返回,我希望他直接进入第二个活动。使用共享首选项
public class spash_scr extends Activity {
ImageView t;
//LoginButton b;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.spash_scr);
// bm1=drawable.shineme;
t = (ImageView) findViewById(R.id.textView1);
t.setImageResource(R.drawable.shineme);
RotateAnimation r = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
// r.setStartOffset(1000);
r.setDuration(2000);
r.setFillAfter(true);
t.startAnimation(r);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent i = new Intent(spash_scr.this, MainActivity.class);
startActivity(i);
finish();
}
}, 3000);
}
Intent intent = new Intent(this, HomeActivity.class);
startActivity(intent);
this.finish ();