Android: userId - GET PHP alternative? - android

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");

Related

Android back to activity after validate

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.

Correct way to track users and logout app

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");

Which function does intent have? [duplicate]

This question already has answers here:
What is an Intent in Android?
(14 answers)
Closed 8 years ago.
I dont know much about intent (or android) so.. Can someone please explain me what is it exactly? i have search on the internet, A LOT.
Also what does each line of this code do?
Intent intent = new Intent (this, DisplayMessageActivity.class);
intent.putExtra("a", "b");
Thanks in advance
I suggest reading Android Intents
You couldn't have search for very long, since this is very basic topic.
I suggest you read more of Android's API guides.
Line 1 = Create message that describes what to do, in this case start "DisplayMessagActivity"
Line 2 = Add content to the message
Intent intent = new Intent (this, DisplayMessageActivity.class);
For this line, its function is to create a navigation from the current activity/page to the displaymessageactivity page.
it is like from here to there.
For this intent.putExtra("a", "b"); the purpose of this is to put like a temp storage/variable to pass to the next page for retrieval. In this case, you put the value "b" in the variable "a". With this method, you can use the value on the other activity or page.
All the above are just storing of info, it is not executed yet. if you want to execute the intent do the following
startActivity(intent);
The best example to state the behavior of Intent is it behaves like a POSTMAN that delivers message to the stated address.
Whether it may be calling service ,BroadCastRecivers ,Activity they are used in number of occassion.
Intents are asynchronous messages which allow application components
to request functionality from other Android components. Intents allow
you to interact with components from the same applications as well as
with components contributed by other applications. For example, an
activity can start an external activity for taking a picture.
Intents are objects of the android.content.Intent type. Your code can
send them to the Android system defining the components you are
targeting. For example, via the startActivity() method you can define
that the intent should be used to start an activity.
An intent can contain data via a Bundle. This data can be used by the
receiving component.
Intents can be used to start Service, call Activty, call Sub Activity, transfer the data between Activity or retrieve the data from Activity

How to display a welcome message including username from another activity in android?

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.

Android Activity choose

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

Categories

Resources