【发布时间】:2016-05-04 14:01:00
【问题描述】:
我只想在应用程序首次启动时启动启动画面。我的初始屏幕与另一个屏幕链接,该屏幕也是第一次出现。 我的启动画面代码是:
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 开始。 现在我想做的是,当我第一次打开应用程序时,只启动主活动(启动画面和与启动画面链接的屏幕现在消失了)
我使用此代码,以便当再次打开应用程序时,布尔值返回 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>
【问题讨论】:
标签: android sharedpreferences splash-screen launcher