-1

I just learn android development few weeks ago and I have a simple question :

let's say I want to build an app just like Facebook which has LoginActivity and NewsFeedActivity.

if user already logged in, then NewsFeedActivity will become default screen whenever user open the app.

so, in this case, what is the best scenario for MainActivity? is it Login screen or News Feed?

thank you

Saint Robson
  • 5,475
  • 18
  • 71
  • 118

7 Answers7

2

Normally first screen we call it splash screen where we collect user information and any remote config we required this screen call only first time only when app launches and after that flow goes to login screen after successful login you can maintain and flag in shared Preference like( Boolean isUserLoggedIn) and after when user again open apps it will take you to feeds screen.

Flow is like Splash screen(if you want)->LoginScreen(if not logged in)->Feed or HomeSreen.

If user is logged in then SplashScreen->HomeScreen untill user not logout flow always like this only.

I hope i clear your doubt little bit if you feel any problem you can ask me again.Thanks!

Nikhil Sharma
  • 593
  • 7
  • 23
  • 1
    I am talking about normal practice and his concern not about security his question only how he can achieve the flow! Thanks! – Nikhil Sharma Apr 26 '17 at 10:33
  • Not shooting your answer down hence no down vote, just saying that other people read these answers, and to someone who doesn't know anything about security this could be misleading. Rather answer precise and with clarity to avoid any future confusion. – the-ginger-geek Apr 26 '17 at 10:38
  • THanks for your concern ,can you tell me have you ever use private mode in Preference and try to root your phone and fetch that data ???? – Nikhil Sharma Apr 26 '17 at 10:42
  • Yes we have. Here is a post for reference. http://stackoverflow.com/questions/9244318/android-sharedpreference-security – the-ginger-geek Apr 26 '17 at 10:55
  • I am talking about you @Neil not we ? – Nikhil Sharma Apr 26 '17 at 10:59
1

In most applications, MainActivity is the SplashActivity. While user is on your SplashActivity, you can decide to navigate user into right scenario based on your business logic.

Erdem
  • 187
  • 1
  • 9
1

The best thing to do would be to make the login activity the launcher acivity. If the user is logged in , it takes you to the news feed activity.

Dishonered
  • 8,449
  • 9
  • 37
  • 50
1

Consider MainActivity as the App Luncher activity. Whenever the app is launched it should be called.

In the MainActivity you can navigate to the other activities based on various factors. For example, if he is already logged in take him to the newsfeed, if not to the login activity.

Based on how long you are going to stay in the MainActivity you can add a layout to it and use it as a splash screen.

Hope it helps.

Hariharan Ayyasamy
  • 287
  • 1
  • 2
  • 14
1

Say you would have an LoginActivity which does the login verification and redirects to news feed (NewsFeedActivity).

Inside your LoginActivity which would be your main activity when user has not logged in yet, you would check for some authentication by using OAuth2, based on which you decide whether user is valid or not.

The OAuth2 token has a validity period, so next time user logins before the token expires all the authentication checks are not performed again, and directly redirected to NewsFeedActivity.

If user is valid the LoginActivity will start a new activity ) based on who the user is.

It depends on how you design your application in the end. There is no one way to do this.

sai
  • 434
  • 5
  • 13
0

For my normal practice, there is a BaseActivity in the app, for those function always needed in every activity. LoginActivity and NewFeedActivity should extends BaseActivity. When launching the app, you may have a landing activity, so redirect to NewFeedActivity if logined, else loginActivity.

Kelly C.
  • 15
  • 6
0

In android there are only activities, each one can be of any name including MainActivity. You shouldn't be concerned about the MainActivity concept at all. You can have two activities, LoginActivity and NewsFeedActivity (Maybe one more activity called SplashActivity, hope you're already have an idea about splash screen or you can look it up). Within newsfeed you can have different fragments for each tab.

Aldrin Joe Mathew
  • 472
  • 1
  • 4
  • 13