1

我有三张图片,我希望它们像启动视图一样出现在第一个布局 xml 中,以便它们只能被查看一次,即当安装 app get 或 app get 是新更新时,该活动只会被调用一次,否则 app 应该总是从第二个活动开始,我不知道我应该如何开始:

在此处输入图像描述

谁能告诉我如何做到这一点。

只显示一次飞溅。

这个问题的下一部分在这里

编码将不胜感激。

4

3 回答 3

4

完成欢迎屏幕内容后,在启动应用程序时在首选项中保存一个标志。在显示欢迎屏幕之前检查此标志。如果标志存在(换句话说,如果不是第一次),不要显示它。

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
    }

}
于 2013-04-23T07:30:52.123 回答
0

为此,您必须检测应用程序的首次启动。为此,您可以按照@Nirav 的建议存储一个布尔值。

对于闪屏,您可以考虑使用FragmentsViewPager创建一个仅在第一次显示的活动

于 2013-04-23T07:41:31.370 回答
0

尝试这个 :

     public class MainActivity extends Activity {

private Thread mSplashThread;

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

        final MainActivity sPlashScreen = this;

        mSplashThread = new Thread() {
            @Override
            public void run() {
                try {
                    synchronized (this) {
                        wait(4000);
                    }
                } catch (InterruptedException ex) {
                }

                finish();
                Intent intent = new Intent();
                intent.setClass(sPlashScreen, StartNewActivity.class);// <-- Activity you want to start after Splash
                startActivity(intent);
            }
        };

        mSplashThread.start();
    } catch (Exception e) {
    }
}

@Override
public boolean onTouchEvent(MotionEvent evt) {
    try {
        if (evt.getAction() == MotionEvent.ACTION_DOWN) {
            synchronized (mSplashThread) {
                mSplashThread.notifyAll();
            }
        }
    } catch (Exception e) {
    }
    return true;

}

}

你放一张图片splash.xml来显示

于 2013-04-23T07:28:55.450 回答