Right now I am trying to implement different main activity of the app depending on the role of the user that is stored at the server-side database. Upon login it is returned to device.
Here Single application with different UIs depending on the user's role there was a similar topic to what I would like to achieve, but it did not offer what I wanted to achieve.
What I do is loading the login activity in MainActivity's onCreate(). After that I check the role and depending on this I use:
if (some condition here){
//here I set the activity_main.xml
} else if (condition again) {
//another variant of activity_main.xml
}
Is this the correct variant to do this? If not, are there any other ways to achieve this? By the way, when I connect user interface elements to xml's values outside of the corresponding conditional block, I keep getting a NullPointerException later on, even if I use the login credentials for the most privileged user, whose interface has the maximum elements (names of views are the same in all xml layouts, files only differ in number of elements).
Sure thing, I know I will be advised to use the login screen as the main one of my app (like the link above suggested), but the app is not going to require login every time it is started, and thus I do not really understand how to realise all this stuff.
Any help is appreciated.