开发者

Proper way of coding

I am n开发者_如何学编程ew in developing android applications. I want to create an android application(using eclipse) which needs a login page where the user needs to put his/her username and password and when the username and password is correct the application will open the main page. I already made a layout for the login page. My question is, is it proper to put the function codes of login and main page in the same package?


Ideally you would define a Login Activity which handles all the Login action, save it in preferences etc and then have it start the MAIN activity when the user is logged in.


yes if they are meant to ship together that'll be easiest


Well, there is no problem in putting the login code and code for the main activity in the same package.

However, to provide the login functionality, you should ask the user login credentials the first time. On successful authentication, you should save it either in your database or in Preferences (preferable). I myself save the authentication details in a preference file. You can even encrypt the saved details if you are too much conscious.

So the next time when the user tries to run your app requiring authentication, it should first check as to whether the credentials are saved in database/Preferences.. if yes, then use those details for login, else perform fresh authentication.

Hope this helps.

Regards, Mahendra Liya.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜