一次闪屏
one time splash screen
我希望我的启动画面只在第一次启动时显示。我知道我必须通过共享偏好,但如何?这是我的标语:
public class Splash extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splash);
//animation
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Animation alpha = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_in);
imageView.startAnimation(alpha);
alpha.setAnimationListener((new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Start your activity here.
Intent mainIntent = new Intent(Splash.this, MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}));
}
}
试试这个:
SharedPreferences mPrefs;
final boolean mLoginSession;
public static final String PREFER_NAME = "MyPrefsFile";
//Inside onCreate
mPrefs = getSharedPreferences(PREFER_NAME, MODE_PRIVATE);
mLoginSession = mPrefs.getBoolean(PREFER_NAME, false);
if (mLoginSession) {
Intent gotoMain = new Intent(Splash.this, MainActivity.class);
startActivity(gotoMain);
finish();
} else {
//Show Splash Data here and Change the shared value of "PREFER_NAME"
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(PREFER_NAME, true);
editor.commit();
}
这样试试。
public class Splash extends Activity {
SharedPreferences sharedpreferences;
boolean splash;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
sharedpreferences = getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
splash = sharedpreferences.getBoolean("Splash", false);
if (splash == true) {
Intent mainIntent = new Intent(Splash.this, MainActivity.class);
startActivity(mainIntent);
}
else
{
setContentView(R.layout.splash);
//animation
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Animation alpha = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_in);
imageView.startAnimation(alpha);
alpha.setAnimationListener((new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Start your activity here.
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean("Splash", true);
Intent mainIntent = new Intent(Splash.this, MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}));
}
}
}
我希望我的启动画面只在第一次启动时显示。我知道我必须通过共享偏好,但如何?这是我的标语:
public class Splash extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splash);
//animation
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Animation alpha = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_in);
imageView.startAnimation(alpha);
alpha.setAnimationListener((new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Start your activity here.
Intent mainIntent = new Intent(Splash.this, MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}));
}
}
试试这个:
SharedPreferences mPrefs;
final boolean mLoginSession;
public static final String PREFER_NAME = "MyPrefsFile";
//Inside onCreate
mPrefs = getSharedPreferences(PREFER_NAME, MODE_PRIVATE);
mLoginSession = mPrefs.getBoolean(PREFER_NAME, false);
if (mLoginSession) {
Intent gotoMain = new Intent(Splash.this, MainActivity.class);
startActivity(gotoMain);
finish();
} else {
//Show Splash Data here and Change the shared value of "PREFER_NAME"
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(PREFER_NAME, true);
editor.commit();
}
这样试试。
public class Splash extends Activity {
SharedPreferences sharedpreferences;
boolean splash;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
sharedpreferences = getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
splash = sharedpreferences.getBoolean("Splash", false);
if (splash == true) {
Intent mainIntent = new Intent(Splash.this, MainActivity.class);
startActivity(mainIntent);
}
else
{
setContentView(R.layout.splash);
//animation
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Animation alpha = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_in);
imageView.startAnimation(alpha);
alpha.setAnimationListener((new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Start your activity here.
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean("Splash", true);
Intent mainIntent = new Intent(Splash.this, MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}));
}
}
}