欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 使用SharePerference判斷是否為第一次登陸的實(shí)現(xiàn)代碼

 更新時(shí)間:2017年03月10日 14:02:03   作者:BrcLi  
很多app中在第一次安裝登陸時(shí)會(huì)有引導(dǎo)歡迎界面,第二次打開時(shí)就不再顯示引導(dǎo)頁面。這個(gè)怎么實(shí)現(xiàn)呢?下面小編給大家介紹下使用SharePerference判斷是否為第一次登陸的實(shí)現(xiàn)代碼,需要的的朋友參考下吧

很多app中在第一次安裝登陸時(shí)會(huì)有引導(dǎo)歡迎界面,第二次打開時(shí)就不再顯示引導(dǎo)頁面。

這個(gè)功能可以通過使用SharePreferences將用戶的登陸信息保存起來,當(dāng)app啟動(dòng)時(shí)判斷登陸信息決定打開頁面。

以下是創(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判斷是否為第一次登陸的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論