启动屏幕重定向错误的活动android
基本上,我有一个启动页面的处理程序,在5秒钟后重定向到主菜单 然而,我也有一个设置页面,这是第一次安装时看到的,但发生的是,它认为这是一个启动页面,并在x秒后重定向。我需要这个在x秒时不重定向,只需要启动屏幕“MainActivity”重定向 主要问题: 第一次安装程序加载首选项。 问题:它在5秒后重定向 应该发生什么: 第一次安装程序加载首选项。 允许用户输入详细信息并保存。 在下一次启动时,会出现启动页面,该页面会在5秒钟后重定向 这是我的密码:启动屏幕重定向错误的活动android,android,redirect,Android,Redirect,基本上,我有一个启动页面的处理程序,在5秒钟后重定向到主菜单 然而,我也有一个设置页面,这是第一次安装时看到的,但发生的是,它认为这是一个启动页面,并在x秒后重定向。我需要这个在x秒时不重定向,只需要启动屏幕“MainActivity”重定向 主要问题: 第一次安装程序加载首选项。 问题:它在5秒后重定向 应该发生什么: 第一次安装程序加载首选项。 允许用户输入详细信息并保存。 在下一次启动时,会出现启动页面,该页面会在5秒钟后重定向 这是我的密码: public class MainActiv
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();
}
}
我重新整理了你的代码,告诉你想要发生什么 应该发生什么:第一次安装加载首选项。允许用户输入详细信息并保存。在下一次启动时,会出现启动页面,该页面会在5秒钟后重定向
据我所知,这应该能解决你的问题
public class MainActivity extends Activity {
private static final int REQUESTCODE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainactivity);
Toast.makeText(this, "MainActivity", Toast.LENGTH_SHORT).show();
// get shared preferences
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
// first time run?
if (pref.getBoolean("firstTimeRun", true)) {
// start the preferences activity
startActivityForResult(new Intent(getBaseContext(),Preference.class), REQUESTCODE);
// get the preferences editor
SharedPreferences.Editor editor = pref.edit();
// avoid for next run
editor.putBoolean("firstTimeRun", false);
editor.commit();
} else {
startMainMenu();
}
}
public void startMainMenu() {
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);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUESTCODE) {
if (resultCode == Activity.RESULT_OK) {
startMainMenu();
}
}
}
}
在设置首选项调用函数“setResult”后的首选项活动中
public class Preference extends Activity{
@Override
protected void onCreate(Bundle savedInstance){
/**
Add necessary preferences to shared preference
**/
if(sharedPreference successfully entered){
setResult(RESULT_OK);
}else{
setResult(RESULT_CANCELED);
}
finish();
}
欲知详情
我希望这对您有所帮助…您是否尝试将“活动结果”设置为“首选活动结果”\u OK无法理解您的问题。你不需要在活动的上下文中开始一个意图。不要使用模糊的术语,指定确切的问题!添加了一个更好的描述,这类修复了它,设置后会发生什么,它进入启动屏幕,不会重定向。在“首选项”菜单加载main菜单之后,我怎么说呢?如果您想在“首选项”之后加载main菜单,然后在“主活动”中覆盖onactivityresult,并在子活动完成后加载主菜单。调用“父活动”时加载主菜单。对此,我很困惑。怎么做?没有工作:保存首选项后,只是停留在启动屏幕上。不去MainMenuNo不知道该怎么办
public class Preference extends Activity{
@Override
protected void onCreate(Bundle savedInstance){
/**
Add necessary preferences to shared preference
**/
if(sharedPreference successfully entered){
setResult(RESULT_OK);
}else{
setResult(RESULT_CANCELED);
}
finish();