开发者

Adding the id during the installation of the android app

Hello please guide me about this query . i am making the android app , in which the user will give his personal no and after contacting with server , the app will show all avaliable services for him . we can say it as a user id . The thing i am wondering about is that how we give the id during the installation of apk file . i mean to say when the user is installing the app it will ask for the personal no and for the rest of the time there is no need to give the personal no , and later on how easily i can fetch开发者_运维技巧 the id to query the records at server side .Thanks


You can't ask anything during installation process. But you can ask user for his ID on first run of your app, and then just store it in SharedPreferences.


When the activity first launched, retrieve from the shared preferences:

SharedPreferences sharedPref = getSharedPreferences("user",MODE_PRIVATE);
String userID = sharedPref.getString("ID","null");

If it is a first timer, userID will have a null value.

if(userID == null && userID.length() == 0){
 //Do a post to web server
 //Retrieve user ID created from web server and store it in shared preference
SharedPreferences sharedPref = getSharedPreferences("user",MODE_PRIVATE);
SharedPreferences.Editor prefEditor = sharedPref.edit();
prefEditor.putString("userID", userIdFromWeb);
prefEditor.commit();
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜