Android OAuth implementation makes receiving share activity stop - android

I have a problem with a activity where onStop breaks my OAuth authentication process.
First a small explanation about the context of my app:
I have this activity (lets call it the receiveSharedDataActivity) which handles incoming data which is being send from other apps. This activity is made using the following example from the Android Developer site: http://developer.android.com/training/sharing/receive.html.
My app requires the user to be logged in using a E-mail and a password or using the Facebook or Twitter OAuth login. It is possible that the user has never opened the app and thus is not logged in yet. (The possibility is small, but it can still occur.)
The problem (challenge):
So when the user decides to share some data to my app but is not logged in yet, I show him the 3 login options (E-mail, Facebook, and Twitter) in the receiveSharedDataActivity using fragments. This way he can first authenticate himself and after that the data can be handled. When the user chooses to login with Facebook the Twitter OAuth login option he is redirected to a new activity from Facebook or Twitter where he needs to login and give my app permission to access his user data. All goes well up to this point. Because when the user is redirected to this new activity, the receiveSharedDataActivity is automatically being stopped using onStop because it is no longer visible to the user. When the user then logs in at the Facebook or Twitter activity and is being send back to the receiveSharedDataActivity, there is no receiveSharedDataActivity anymore because it has stopped. So the user ends up at another app where the user decided to share data from.
The question:
How can I prevent the receiveSharedDataActivity from being stopped when the user is login in at the Facebook or Twitter activity?
I am looking forward to your solutions because I am pretty stuck with this problem.

Good news! I was able to solve this issue. All this time I thought that it had to do with passing the correct Intent flags when starting the receiveSharedDataActivity. Silly me...
The problem was that my receiveSharedDataActivity had the noHistory:true parameter set in the AndroidManifest.xml. I needed this because obviously I did not want this activity to be added to the backstack. But the noHistory parameter made my activity destroy itself directly after the activity was no longer visible to the user. Which happend when the OAuth login activity started. So of course there was no activity to return to after the OAuth login activity was completed because the receiveSharedDataActivity was simply destroyed.
When I removed the noHistory parameter, the activity did not destory itself anymore and nicely called the onRestart method where I could now handle the rest of the Oauth process. And I was able to prevent the activity from being added to the backstack just by calling finish() right after starting a new activity. This way the activity destroys itself and does not get added to the backstack.

Related

How to implement auto login?

I have my app, first time its opened it opens splash screen ( activity 1) and moves to second page(activity 2) to ask for username/password.User loggs in i save things in sharedpreferences ( sessionid). Later when the app is closed, and reopened same thing splash screen(activity 1) is opened however this time since user already logged in ( i get to read sessionid via sharedpreferences on splash screen) i automatically take him in to activity 3.
My problem is , i am doing on splash screen the check whether he is already logged in or not. i want to remove splash screen (activity 1) part. open the login screen first time ( activity 2), and if its logged in second time it opens the app directly to (activity 3).
How can I do this? Just like gmail?
Move your authentication code to another class. The authentication class should handle the caching of the username and password and handle the username and password checking when the user logs in the first time. Before you show the splash screen check have a method which checks if the user is cached. If the user is then go directly to activity three. If not then show the splash screen and allow the user to login. The login activity will also use the authentication class to validate the username and password.
I have solve this issue in my mobile app.
I have use in my mobile app first time login using username/email and password with login application after successfully login store data in session and also in url pass authentication key use so after some time my session destroy but in this case i have retrieve data using my unique authentication key so not redirect login page after session destroyed and if remove mobile cache then redirect login page.

Running Facebook Login / Publish as Seperate Class

I have followed : https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/
I have created a separate page as in the example and works perfectly fine.
My issue is now I want to add the Login button to my home page and the publish button on a different page. Is it possible to convert this into a separate class that I can call from anywhere?
Has anyone done this and can point my in the right direction.
Sorry if this has been asked before. I am very new to Facebook SDK
Thanks for your time
Yes, if you use the Active Session, you should be able to call Session.getActiveSession() from any activity, and it should return you the right thing. So the page with the login button would create the active session, and the page with the publish button would get the active session, and call requestNewPublishPermission and do the publish.
There are 2 outstanding issues:
You need to ensure that the page with the login button appears in your app before the page with the publish button (at least the first time, when the user initially logs in).
In subsequent restarts of your app (after the user has already logged in), you can use the UiLifecycleHelper to manage, restore, and auto-open the active session for you.

Returning to the activity after logging into facebook

My question is how the user can return automatically to the activity he was using after logging into facebook ...
I mean that there are some activities that need to log into facebook, so the user moves into the login page . but when the user finishes it doesn't return to the application
How can be this solved?
it is up to your app to detect the url changes in the webview , intercept the facebook response , and then if success restart the pending operation that is why you would consider ask for login at startup and avoid all that complexity

How to implement login activity that available in all activity. android

In my application I have more that 20 activities and I want to ask for log in on particular operation on all activity if user is not logged in but not getting any idea where to start. I am using three method for login first my website login,second google and third is facebook. User can pick any to log in.
Create an activity which will contain function that would be common to all activity like login handler and extend that activity from your existing activities.
You can check for validity of the sessionId before launching anything. If valid, launch activity. Else, launch Login page.
You can send broadcast, when you want to ask user for login. Then, in BroadcastReceiver you'll create your login activity, start it and wait for result (which also can be sent back by intent).

Android Login - Best implementation

I'm planning to implement an Android application that requires a login screen.
If the user opens the activity something like this should happen:
If user is logged in, goto 3
If user is not logged in open the login screen and perfom login
Show my application content
So, what's the "correct" way of implementing a login?
Implement a StartActivity that perfoms the check if the user is logged in, implement a LoginActivity that implements the logging and an ApplicationActivity that actually implements the application logics?
Implement just one Activity and handle the login by using multiple views which I show according to the application state?
Are there any examples or tutorials for this scenario?
I don't think that there is a "correct" way of doing this. Both solutions you describe seem fine to me, although I would merge StartActivity and LoginActivity into a single one.
You can even just have a MainActivity that shows a Login Dialog. You could store the user's login/password with SharedPreferences, and on app start check the preferences and auto-login the user or else show the login dialog. If you do this you should also add a logout functionality.
I had developed a microblogging application recently which had a login activity and which on logging in redirects user to his home page.
The way, I did it was to keep the login activity and Application Activity separate and if the user supplied credentials were right, the application activity was started by
startActivity(new Intent(LoginActivity.this, ApplicationActivity.class)
Later on I added a Checked Box and on ticking it, the user name and password were written to SharedPreferences and so the next time onwards user was straightaway directed to his home page.
Login Activity : Taken you to the login screen if user is not logged in. Check SharedPreference for logged in user. If user is logged in, it will open up Application Activity.
ApplicationActivity : The landing page of your application.

Categories

Resources