我希望登录活动在用户启动应用程序但尚未登录之前启动.如果之前已成功完成登录,则应用程序将跳过登录页面并移至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);
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了FCs.我是如何实现SharedPreferences的?
Hei*_*upp 14
您的代码从不调用它first_time_check(),因此在返回用户的情况下自动转发不起作用.
你可以onCreate()做到
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
first_time_check();
setContentView(R.layout.configure);
...}
Run Code Online (Sandbox Code Playgroud)
因此,对于新用户,first_time_check()将他转发到登录页面,否则将显示当前布局并且他可以继续在该页面上.
小智 5
您正在使用共享首选项.那很好.
这个链接给出了一个小例子.这可能会解决问题.
http://developer.android.com/guide/topics/data/data-storage.html
基本上,我没有看到你读取存储的价值.您正在存储它然后提交它.但是没有代码在哪里阅读它.只有在您阅读它时,您才能决定必须启动哪个活动.你必须调用first_time_check()来解决这个问题.
希望我能帮到你.
| 归档时间: |
|
| 查看次数: |
37823 次 |
| 最近记录: |