我想在第一次启动应用程序时启动我的启动画面。我的启动画面与另一个屏幕相关联,这也是第一次出现。 我的Splash Screen代码是:
public class SplashPage extends Activity{
private static int startPage = 7000;
SharedPreferences prefs = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashpage);
prefs = getSharedPreferences("com.tech.spam", MODE_PRIVATE);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if (prefs.getBoolean("firstrun", true)) {
calll();
}
if (prefs.getBoolean("firstrun", false)) {
finish();
startActivity(new Intent(SplashPage.this,MainActivity.class));
}
//prefs.edit().putBoolean("firstrun", false).commit();
//finish();
}
private void calll() {
// TODO Auto-generated method stub
Animation anim = AnimationUtils.loadAnimation(this, R.anim.move);
ImageView iv = (ImageView) findViewById(R.id.imageView1);
iv.startAnimation(anim);
Animation anim1 = AnimationUtils.loadAnimation(this, R.anim.move);
TextView ivvv = (TextView) findViewById(R.id.textView1);
ivvv.startAnimation(anim1);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent(SplashPage.this, SplashPageTutorial.class);
startActivity(intent);
overridePendingTransition(R.anim.fade, R.anim.hold);
finish();
}
},
startPage);
}
现在我想要做的是第一次启动应用程序时Splash运行7秒,然后下一个屏幕打开,在7秒后与启动相关联,然后在第二个屏幕后我的主Activity启动。 现在我想做的是,当我第一次打开应用程序时,只有主要活动启动(启动画面和与启动链接的屏幕现在已经消失)
我使用这段代码,以便当app再次打开时,boolean返回false并启动Main Activity但不会发生
if (prefs.getBoolean("firstrun", true)) {
calll();
}
if (prefs.getBoolean("firstrun", false)) {
finish();
startActivity(new Intent(SplashPage.this,MainActivity.class));
}
//prefs.edit().putBoolean("firstrun", false).commit();
//finish();
请帮助我该怎么做
我的清单就是这样:
<application android:icon="@drawable/appicon"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme">
<activity android:name="com.tech.spam.SplashPage"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.tech.spam.MainActivity"
>
</activity>
<activity
android:name="com.tech.spam.SplashPageTutorial"
android:theme="@style/FullscreenTheme"
>
</activity>
答案 0 :(得分:3)
一种简单的方法是拥有共享首选项变量。启动启动屏幕时,将此变量设置为true。在启动活动之前,请检查此变量是否为false,如果为false则仅启动。
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
SharedPreferences settings=getSharedPreferences("prefs",0);
boolean firstRun=settings.getBoolean("firstRun",false);
if(firstRun==false)//if running for first time
//Splash will load for first time
{
SharedPreferences.Editor editor=settings.edit();
editor.putBoolean("firstRun",true);
editor.commit();
Intent i=new Intent(check.this,Splash.class);
startActivity(i);
finish();
}
else
{
Intent a=new Intent(check.this,Main.class);
startActivity(a); // Launch next activity
finish();
}
}
}