I've been trying to add a custom account to my app so I can manage the authToken to my server better, but I'm confused as to initialise eveything properly.
I've created the Authentication Activity that allows the user to log in, the Authenticator and the service, but I'm not sure how to go about handling the first time the app is opened.
The Authenticator will display the AuthActivty when it doesn't have the users account details, but in the case where the app is opened the first time, the account type doesnt exist in the phone, so I'm unable to call the getAuthToken method in the Authenticator.
Should I check if the account type exists and manually start the LoginAcivity from my MainActivty or am I missing something?
You should actually have a OOBE flow for first time launch where in you can include this.
That means, your launcher should not be main activity. Instead, it could be a spashscreen activity that can decide on whether to go to main activity or take first time launch flow
Related
Background:
I've successfully added Google authentication to my website. There's a Login button that works (and stores the user from the db into the session) as well as a Logout button that logs out the user from my application, but obviously not from Google also. There's a menu item that reflects that authentication by only displaying the appropriate Login or Logout menu item, plus access to a Profile page if they're authenticated. In my SecurityConfig.filterChain() method, I have
.antMatchers("/secure/**").authenticated()
to ensure users can't get into the secure part of the site (ex: secure/xyz) without being authenticated.
Problem:
However, when a user returns to my website (with a new session) and is still logged into Google, my application thinks the user is authenticated and allows access to the secure URLs, via the browser address bar (ex: secure/xyz), without having to log in again.
I want to know if a user is authenticated when they return to the site, at the very least for UI purposes (displaying Login or Logout). Storing the User in the session is insufficient. I assume I need a SessionListener or a HttpSessionIdListener for this, but I'm not sure what code to put in the sessionCreated() or sessionIdChanged() method to get the identity of the authenticated user. What code do I need?
Well, the actual solution show that I'm still learning. When the user returns back to the site, they are not already authenticated. I thought they were only because I had things in SecurityConfig.filterChain() in the wrong order. Once I put
.antMatchers("/secure/**").authenticated()
at the beginning, everything started working as expected.
When I've signed-out from within the Leaderboards by accessing settings, and when I attempt to sign back in, the application crashes. It seems that GameHelper does not register this sign-out.
How does one fix this?
I believe this is a similar issue that was raised on the github repo. Its indicated there that its working as intended.
When you start a GPGS activity, you have to start it with startActivityForResult. If the user clicks on sign-out, the GoogleApiClient is NOT disconnected - it's just in a "signed out" state. The onActivityResult here will return a status RECONNECT_REQUIRED. At this point, the developer should reconnect their client, and life goes on as expected.
Try to modify the RECONNECT_REQUIRED condition block to disconnect, or create a way to handle it specific to your usecase (log-in page?).
I have login page (activity) which is my first activity (landing page) of the app.
Only after user gives correct username and password, the app allow you go to other pages to work with.
Now my question is, now the user is at the fourth page and he is working on it, And he minimize the app and use other app like messaging etc..
so when he come back to click my app icon again, my app starts from the first landing page, which is the login page,
how can I make my app to resume from the fourth page?
Android 4.4.4, Kit Kat, Samsung
Regards,
Nay TK
Add this in android manifest of loginActivity,
android:launchMode="singleTask"
more on android:launchMode
An instruction on how the activity should be launched. There are four modes that work in conjunction with activity flags (FLAG_ACTIVITY_* constants) in Intent objects to determine what should happen when the activity is called upon to handle an intent. They are:
"standard"
"singleTop"
"singleTask"
"singleInstance"
The system creates the activity at the root of a new task and routes
the intent to it. However, if an instance of the activity already
exists, the system routes the intent to existing instance through a
call to its onNewIntent() method, rather than creating a new one.
go through official link for more detail
You can make your fourth activity as your launch activity.
In the Resume of your Activity, you check if the user is logged in. If not, you start your Login activity.
I have a project setup. https://github.com/Axiom1999/Iron-Banner-Companion/blob/master/app/src/main/java/me/axiom/aapp/ironbannercompanion/
And I have a button which I need to check with the API if the username on the platform exists and if it can get information then start the MainActivity intent.
I do not know how to initially start the connection.
You can use LoginActivity for checking if user already exists. Check this out in onCreate() (i think the best way keep this data in SharedPreferences). If user exists try to login and show LoginActivity with ProgressBar. If user does not exists simply show Login/SignUpActivity
let me start off by saying happy holidays to everyone!
ok i really just need confirmation and correction if needed.
what im trying to do:
Im using google and facebook "Log-in" feature to sign in for my app to retrieve the data needed like name email etc.
where i Need help:
after signing in i want another activity to be the forefront everytime app opens unless the user signs out then of course, it takes them back to the original main page to sign back in.
now im assuming this takes place in maybe the lifecycle right?
somthing like:
#override
OnResume
{
//if user is signed in cast an Intent to automatically go to another activity?
}
am i on the right track on no? thanks in advance guys
I'm not sure off the top of my head how Google and Facebook's login is implemented... do they have a sample project you're using?
And yep, you're on the right track! Generally speaking you should be able to have a "Main" activity (MainActivity for this example) which checks to see if the login was successful, and if so, kicks you to the activity you want (LoggedInActivity).
This would be in the onCreate() or onResume() method of MainActivity.java
onResume() { // onCreate() should work, too.
if (loggedIn) {
startActivity(new Intent(this, LoggedInActivity.class));
} else {
// send them to login
}
}
If there's not a good way to check if they're logged in, you could save a boolean value or api token using SharedPreferences once the login is successful, and check that value (that'd be the value of loggedIn) every time at launch. You'd obviously need to clear that value any time you logged out.