Android 使用SharePerference判斷是否為第一次登陸的實現(xiàn)代碼
很多app中在第一次安裝登陸時會有引導(dǎo)歡迎界面,第二次打開時就不再顯示引導(dǎo)頁面。
這個功能可以通過使用SharePreferences將用戶的登陸信息保存起來,當(dāng)app啟動時判斷登陸信息決定打開頁面。
以下是創(chuàng)建的SharePreference類:
public class SharePreference { Context context; public SharePreference(Context context) { this.context = context; } /****設(shè)置狀態(tài) false為安裝后第一次登錄,true為已經(jīng)登錄過****/ public void setState() { SharedPreferences sp = context.getSharedPreferences("save.himi", Context.MODE_PRIVATE); Editor editor = sp.edit(); editor.putBoolean("isLogin", true); editor.commit(); } /***獲取狀態(tài)***/ public boolean getState() { SharedPreferences sp = context.getSharedPreferences("save.himi", Context.MODE_PRIVATE); boolean b = sp.getBoolean("isLogin", false); return b; } }
在app打開前可以獲取登陸狀態(tài),選擇展示界面:
isLogin = sp.getState(); if(isLogin){ intent = new Intent(this,Activity1.class); } else { sp.setState();<span style="white-space:pre"> </span>//將登陸狀態(tài)設(shè)置為true; intent = new Intent(this,Activity2.class); }
以上所述是小編給大家介紹的Android 使用SharePerference判斷是否為第一次登陸的實現(xiàn)代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Kotlin協(xié)程操作之創(chuàng)建啟動掛起恢復(fù)詳解
本文的定位是協(xié)程的創(chuàng)建、啟動、掛起、恢復(fù),也會示例一些簡單的使用,這里不對suspend講解,,也不對協(xié)程的高級用法做闡述(熱數(shù)據(jù)通道Channel、冷數(shù)據(jù)流Flow...),本文主要講協(xié)程稍微深入的全面知識2022-08-08GuideView的封裝實現(xiàn)app功能引導(dǎo)頁
這篇文章主要為大家詳細(xì)介紹了GuideView的封裝實現(xiàn)app功能引導(dǎo)頁,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-03-03android SQLite數(shù)據(jù)庫總結(jié)
本文主要介紹了android SQLite數(shù)據(jù)庫的相關(guān)知識。具有一定的參考價值,下面跟著小編一起來看下吧2017-01-01