У меня есть 3 Активность:Как настроить SharedPreferences для первого запуска активности в Android?
1- SplashScreensActivity
2- IntroActivity
3- MainActivity
мне нужно сделать, при первом запуске appliation начать IntroActivity еще MainActivity после SplashScreenActivity.
Отредактировано:
Я написал этот код, но не работает, и после показа экрана заставки, MainActivity работы и IntroActivity никогда не начинать.
Plese дал мне знать, где проблема.
Intro.Java:
SharedPreferences settings=getSharedPreferences("prefs", 0);
final boolean firstRun=settings.getBoolean("firstRun",false);
if(firstRun==false)
{
SharedPreferences.Editor editor=settings.edit();
editor.putBoolean("firstRun",true);
editor.commit();
Intent i=new Intent(Intro.this,Intro.class);
startActivity(i);
finish();
}
else
{
Intent a=new Intent(Intro.this,MainActivity.class);
startActivity(a);
finish();
}
SplashScreeActivity.Java:
public class SplashScreensActivity extends Activity {
private ImageView mLogo;
private TextView welcomeText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash_screen);
Typeface roboto_s = Typeface.createFromAsset(getAssets(), "Roboto-Thin.ttf");
mLogo = (ImageView) findViewById(R.id.logo_sp);
welcomeText = (TextView) findViewById(R.id.welcome_text);
welcomeText.setTypeface(roboto_s);
Animation animation2;{
mLogo.setAlpha(1.0F);
Animation anim = AnimationUtils.loadAnimation(this, R.anim.translate_top_to_center);
mLogo.startAnimation(anim);
}
Animation animation3; {
ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(welcomeText, "alpha", 0.0F, 1.0F);
alphaAnimation.setStartDelay(700);
alphaAnimation.setDuration(1200);
alphaAnimation.start();
}
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
finish();
Intent next = new Intent(getBaseContext(), Intro.class);//
startActivity(next);
}
}, 2000);
}
}
вы можете добавить вывод журнала? –
Да, пожалуйста, подождите минутку –
кстати. это код в SplashScreensActivity? –