开发者

I have two radio buttons if the user wants to keep his account logged in [duplicate]

This question alread开发者_Python百科y has answers here: Closed 11 years ago.

Possible Duplicate:

I'm working on having a "Keep me on Logged in" state on my app. How should i do it?

I got the yes button working like if the user logs in and closes the app when he opens it the user goes directly to the main page. My problem is, what if the user chose not to keep his account logged in, i want the activity to start at the log-in page again when the user opens the app again


Login activity set as the main activity for starting point of your application now first time you login you can set this setting into the SharedPreference like if I set the yes then in SharedPreference set keeplogin as key and it's value true and check every time when he was start the application first fetch this value using the key from the SharedPreference compare if true then start your another activity otherwise continue with this login screen

here is the e.g.

preferences = PreferenceManager.getDefaultSharedPreferences(this);

editor = preferences.edit();

here first time check this key was not found and the condition was wrong and continue with the logi screen. now if you set to true then this condition always true and redirect to the another activity. if you set to false then always start with the login screen

if(preferences.getBoolean("KeepLogin", "")){
   intent = new Intent(getApplicationContext(),HomeActivity.class);
   startActivity(intent);
   finish(); 
}

/////// when click on the login button set the value of your radio button into the login button click event

boolean keeplogin // fetch your radio button status here and set to this object
editor.putBoolean("KeepLogin", keeplogin);
editor.commit();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜