//Give your SharedPreferences file a name and save it to a static variable
public static final String PREFS_NAME = "MyPrefsFile";
अब, विधि का मूल्यांकन करता है कि अगर उपयोगकर्ता को सफलतापूर्वक में लॉग में, निम्न करें। Example
कक्षा पर ध्यान दें, आपको इसे अपने कोड से मेल खाने के लिए बदलना होगा।
//User has successfully logged in, save this information
// We need an Editor object to make preference changes.
SharedPreferences settings = getSharedPreferences(Example.PREFS_NAME, 0); // 0 - for private mode
SharedPreferences.Editor editor = settings.edit();
//Set "hasLoggedIn" to true
editor.putBoolean("hasLoggedIn", true);
// Commit the edits!
editor.commit();
अंत में, जब आपके आवेदन अब आप का मूल्यांकन कर सकते ही उपयोगकर्ता पहले में हो या ना किया गया है शुरू होता है। अभी भी Example
कक्षा को नोटिस करें जिसे आपको बदलना होगा।
SharedPreferences settings = getSharedPreferences(Example.PREFS_NAME, 0);
//Get "hasLoggedIn" value. If the value doesn't exist yet false is returned
boolean hasLoggedIn = settings.getBoolean("hasLoggedIn", false);
if(hasLoggedIn)
{
//Go directly to main activity.
}
आशा इस मदद करता है
संपादित करें: वापसी बटन का प्रयोग वापस प्रवेश गतिविधि आप finish()
लिए एक नया एक शुरू करने के बाद गतिविधि के लिए जाने के लिए से उपयोगकर्ता को रोकने के लिए।
के बाद कोड से Forwarding.java | Android developers
// Here we start the next activity, and then call finish()
// so that our own will stop running and be removed from the
// history stack
Intent intent = new Intent();
intent.setClass(Forwarding.this, ForwardTarget.class);
startActivity(intent);
Example.this.finish();
तो, क्या आप अपने कोड में क्या करना है, प्रवेश गतिविधि पर finish()
समारोह कॉल करने के लिए startActivity()
बुला के बाद है लिया।
यह भी देखें: Removing an activity from the history stack
जिस लिंक को आपने हमारे साथ साझा करने का प्रयास किया वह विकृत था। सही लिंक जोड़ने के लिए कृपया अपना प्रश्न संपादित करें। –