我希望在用户启动应用但之前未登录时启动登录 Activity 。如果之前已经成功登录,应用程序将跳过登录页面并移动到 MainMenu.java。 我现在拥有的是:
public class Login extends Activity implements OnClickListener, TaskCompleteCallback{
first_time_check();
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.configure);
...}
private boolean first_time_check() {
String first = mPreferences.getString("first", null);
if((first == null)){
Intent i = new Intent(Login.this, MainMenu.class);
startActivity(i);
}
return false;
}
...
SharedPreferences.Editor editor = mPreferences.edit();
editor.putString("first", value);
...
editor.commit();
// Close the activity
Intent i = new Intent(Login.this, MainMenu.class);
startActivity(i);
}
但我得到了 FC。我实现 SharedPreferences 的方式有问题吗?
最佳答案
您的代码永远不会调用该 first_time_check()
,因此在返回用户的情况下自动转发不起作用。
你可以在 onCreate()
做
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
first_time_check();
setContentView(R.layout.configure);
...}
所以对于新用户,first_time_check()
会将他转发到登录页面,否则
将显示当前布局,他可以在此页面上继续。
关于Android检查用户之前登录,否则开始登录 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6718514/