开发者

Android: Generic login page returning user to previews view. How?

I would like to make a generic login view. I already got the view and the login itself works fine. The problem I have and could not find a solution is that the user can login from a number of views within my app. I want to make the user return to the previews view where he was and refresh that view after a successful login.

If the user logs in it saves the login data to a flat file (SharedPreferences). Each view checks for a username and password in the flat file. If this does not exist the user is being treated as not logged in. If the user then goes to the login view and successfully logs in, he should be forwarded (or returned) to the previous view he came from. How can I make this work? It's also important that the previous view will be reloaded or at least checks again for the newly saved login information in the fl开发者_运维知识库at file after loggin in.

thanks for any help!


For returning the user to the previous Activity, use:

finish();

For "refreshing" the activities when the user sees them the second time, make sure you are doing your view population in onResume and not onCreate. Check out the Activity Lifecycle for more info.

You want to do one-time setup in onCreate and then do the parts that will need refreshing in onResume. onCreate will be called once when your activity is first created, and onResume will be called every time your user returns to the activity.


I am assuming you mean that you have a view in your app that contains a login form within the same activity. Upon login, you'll want them to go where they were before.

Coming from the other view, you could store it in a variable and upon successful login, setContentView to that View.

Upon successful login, you could run a function called UpdateView that contains the update logic.

You could also serialize the view you want to come back to and save it somewhere until you need it if you really wanted.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜