Android的设置开机画面(活动),如iPhone第一部分 [英] Android Setting Up Splash Screen(Activity) Like Iphone Part1

查看:231
本文介绍了Android的设置开机画面(活动),如iPhone第一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的三个图像,我希望他们能够出现在像泼视图第一个布局XML使他们能只有一次,即该活动被视为只会调用一次,当应用程序获取的安装,或者应用程序获取一个新的更新否则应用程序应该始终从第二个开始的活动,我不知道我应该如何开始的:

I have three images with me and i want them to appear on first layout xml like a splash view so that they can be viewed only once i.e that activity will be called only once when app get's installed or if app get's a new update otherwise app should always start from the Second activity, i don't know how should i begin with this :

任何一个可以告诉我任何想法如何可以做到这一点。

Can any one tell me any idea how this can be done.

要显示启动了一次。

这个问题的下一步的部分是<一个href=\"http://stackoverflow.com/questions/16164132/android-setting-up-splash-screenactivity-like-iphone-part2\">here

Next part of this question is here

编码将大大AP preciated。

Coding will be much appreciated.

推荐答案

保存在preferences一个标志,当你启动应用程序,您已经做了欢迎屏幕之后的东西。检查这个标志告诉你的欢迎屏幕前。如果标志为present(换句话说,如果这不是第一次了),没有表现出来。

In your activity:

SharedPreferences mPrefs;
final String welcomeScreenShownPref = "welcomeScreenShown";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    // second argument is the default to use if the preference can't be found
    Boolean welcomeScreenShown = mPrefs.getBoolean(welcomeScreenShownPref, false);

    if (!welcomeScreenShown) {
        // here you can launch another activity if you like
        // the code below will display a popup

        String whatsNewTitle = getResources().getString(R.string.whatsNewTitle);
        String whatsNewText = getResources().getString(R.string.whatsNewText);
        new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(whatsNewTitle).setMessage(whatsNewText).setPositiveButton(
                R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
        SharedPreferences.Editor editor = mPrefs.edit();
        editor.putBoolean(welcomeScreenShownPref, true);
        editor.commit(); // Very important to save the preference
    }

}

这篇关于Android的设置开机画面(活动),如iPhone第一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆