开发者

implement login window in android app

开发者 https://www.devze.com 2023-02-18 03:17 出处:网络
I am building an android app and would like to implement a login check at start. I am starting a Main activity and there i check if the user is logen in(by calling \"getSharedPreferences\" with my app

I am building an android app and would like to implement a login check at start. I am starting a Main activity and there i check if the user is logen in(by calling "getSharedPreferences" with my application client key. if its empty then i will startActivity(Login.class), from the Login activity i manage the logi开发者_JAVA技巧n, save is in the shared prefernece and then call startActivity(Main.class)

  1. Is using the android "registry" SharedPreferences is a good way of managing if the user is loged in?
  2. Is it a good practice to use startActivity in both activities ? or i should somehow go back to my first Main activity and start the login check again (which will pass this time) or is it what the flag "singleTop" in an activity here for ? the secone start activity will call the first Main i created and not create a new one ?


Question 1. : As long as it is a key and that you check it against a web service or something then it is secure. If it is just a flag that you set, like "logged = 1" then SharedPreference is not implemented with data security in mind. So you can use SharedPreferences but make what you store there secure by yourself.

Question 2. : You should come back to your main activity by finishing the first. You can put to good use the startActivityForResult to good use here. Your login activity would then send back the login result using the Activity.setResult method. You'll then retrieve that result in your first activity using the onActivityResult callback.

0

精彩评论

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

关注公众号