I am trying to code a native app with social logins as you can see the below image.
Now I'm able to authenticate users from my FirstActivity and sending the authenticated users to next SecondActivity.
Here comes my issue.
I have a single logout button on my SecondActivity
Now how do I know which account user clicked and how do I make them logout ?
Any suggestions are most welcome.
In your first activity make a string variable and set it to either facebook or either google + depending upon which the user picks to login. Pass in this variable as an extra with the intent to start the second activity.
So in your first activity you need something like this:
Intent myIntent = new Intent(this, NewActivityClassName.class);
myIntent.putExtra("id","FirstKeyValue");
myIntent.putExtra("name","SecondKeyValue");
startActivity(myIntent);
In your second activity you need something like this to retrieve the value :
Intent intent = getIntent();
String id = intent.getStringExtra("id");
String name = intent.getStringExtra("name");
Related
I created login page with firebase and i use firstore to store some info about the users like ID.
I created 2 types of users: Employer and Worker, When i register as employer, i store custom ID in firestore with 8 letters from the UID of the user and i add in 'e' at first of the string. I do the same thing when Worker register but i add 'w' in at first of the string.
Now when i try login as employer i want to go to certain activity and if i login as worker i want to go to certain activity.
I dont know how to do this,I'd be happy to get help.
The main launch activity can start another activity after login is complete. Edit whereever you want to do the transmission depending on the UID which in this case is either employer or worker. In the end you should be looking into something like this: *(As you provide no code block to help out,
UID = getUID()//your method
Intent intent; //this is the intent you will start
if(UID == employee)//you can use first char to decide here
{
intent = new Intent(this, employer_activity.class);
startActivity(intent);//this will start that activity as employer
}
else if(UID == worker)
{
intent = new Intent(this, worker_activity.class);
startActivity(intent);//this will start that activity as worker
}
I'm making a registration form with 5 steps (5 activities, Similar to facebook signup form).
The 1st activity is to put email
The 2nd activity is to put name and so on. After the user complete all steps, i validate the field email (to avoid being duplicated) from the server side. What i want is, if the user email exist, i want to go back to 1st activity so the user can enter other email and the submit the form again to the server. Whats the best way to do that?
Thanks
In your LastActivity after some action.
Intent intent = new Intent(this,FirstActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent );
This flag clear recent Activity in the activities stack.
so I have an app where users have accounts/profiles, when say you type name and surname in search it would bring to activity called ProfileViewer and display that users details.
In PHP I would have link like:
John Sample
So when user clicks on that - it would go to PHP page called profile.php and load data from MySQL database WHERE userid=xxx.
So what's the alternative in Android? I am a bit lost, what are some of my options on how to identify which userID is Activity loading?
Could I use putExtra("userId", xxx) and then use getExtra()?
In other words: How can I make one activity act like page which accepts 1 param and then uses it on opening?
Intent extras are generally the way to go in these cases.
From the first activity you would:
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("userId", 1);
startActivity(intent);
And you then retrive the information in the second activity like this:
getIntent().getIntExtra("userId");
Here is what I want to do, I have an android login form with username and password, after the user enters his credentials and login, the next form should display on top of the page welcome,+username entered from the login page! can someone please help me??
I'm new to android development and don't know how to go about this. Thanks
You can use intent to pass username from one activity to another.
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtra("username","enteredusername");
startActivity(intent);
And in SecondActivity
String name = getIntent().getStringExtra("username");
Now use the name and display the welcome +name
http://developer.android.com/training/basics/firstapp/starting-activity.html
In order to send data from one activity to another, you need to use intents. So, in your login activity, you would launch your welcome activity like this:
Intent intent = new Intent(LoginActivity.this, WelcomeActivity.class);
intent.putextra("userName","value");
startActivity(intent);
Then, in your welcome activity, you need to retrieve the extra data, like so:
String data= getIntent().getStringExtra("userName");
There are a multitude of examples that can be found via Google, and many questions similar/identical to this have been answered previously on SO.
You can store the username in sqlite or sharedpreferences to get the username across all your application.
I need to choose if I should run one activity or another depends on authorization. If you have no account in AccountManager I want to show RegistrationAcitivity in other situation I want to show LoginActivity. What is the best pattern to do that? Where I need to put the code which is checking that? In one of those activities?
You can check the condition is user is already register then move to AccountManager .
Intent intent = new Intent(this,AccountManager.class);
startActivity(intent);
if not then redirect him to RegistrationAcitivity
Intent intent = new Intent(this,RegistrationActivity.class);
startActivity(intent);
For that you can set flags.
or store data either in SharedPreferences or Database
You can put the code in Registration Activity, check for accounts there and if available redirect him to login activtiy