【发布时间】:2015-02-01 14:32:38
【问题描述】:
基本上我有一个启动页面的处理程序,它会在 5 秒后重定向到主菜单。
但是,我也有一个设置页面,在第一次设置时可以看到,但发生的事情是它认为这是一个启动页面,并在 x 秒后被重定向。我需要这个在 x 秒内不重定向,只需要启动屏幕“MainActivity”重定向。
主要问题:
首次设置会加载首选项。 问题:5 秒后重定向。
应该发生的事情: 第一次设置加载首选项。 允许用户输入详细信息并保存。 下次启动时,会出现启动页面,该页面会在 5 秒后重定向。
这是我的代码:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainactivity);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
final Intent mainIntent = new Intent(MainActivity.this, MainMenu.class);
MainActivity.this.startActivity(mainIntent);
MainActivity.this.finish();
}
}, 5000);
// get shared preferences
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
// first time run?
if (pref.getBoolean("firstTimeRun", true)) {
// start the preferences activity
startActivity(new Intent(getBaseContext(), Preferences.class));
//get the preferences editor
SharedPreferences.Editor editor = pref.edit();
// avoid for next run
editor.putBoolean("firstTimeRun", false);
editor.commit();
}
}
【问题讨论】:
-
无法理解您的问题。而且你不需要 Activity 的上下文来启动一个意图。
-
不要使用模糊的术语,具体说明问题!
-
添加了更好的描述