I am a new android developer trying to create a log-in and register page. I have created both Log-in and Registration pages but i don't know how to add the registration page with the main log-in interface. I have tried to add it but I don't know how to do it. Can anyone let me clear on how to add a page X with another page Y.
Your answers to guide me are welcome.
Create a button in login page suppose btn_login.Then
btn_login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i=new Intent(Loginpage.this,Registration.class);
startActivity(i);
}
});
In this way you can connect two pages using Intent.
For this you can make use of Intents ,Assuming that you have two activities and A button named buttonReg
1.Login Page (Login.java)
2.Registration Page(Register.java)
Create an Intent
For the register page like like
Intent in=new Intent(getApplicationContext(),Register.class);
and start activity in the button click like
buttonReg.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v)
{
startActivity(in);
}
});
And do not forget to add the Activity to your Manifest.xml
For more information about intents goto this tutorial
Related
I have a few activities:
Splash screen
Login
Registration
Dashboard
If the user has never logged in, it will go like this:
Splash screen > Login > Registration > Dashboard
When I back from the Dashboard, it should exit the app, skipping through the other activities.
noHistory on the Login page doesn't work here because sometimes the user will back from Registration.
If the user has previously logged on, it should go like this:
Splash screen > Dashboard
If the user logs out, perhaps to use another account, then it should go:
Dashboard > Login > Dashboard
But if the user goes back from the new Dashboard, it shouldn't enter the previous account's Dashboard.
Aside from that, my app contains multiple modules, some of which don't have access to other modules, so a solution that can work between modules would be helpful.
I have tried a mix of finish() and startActivityForResult() and trying to check where the activities return from but it felt very hacky, time-consuming, and it messes up on new use cases. Are there better ways?
You should do something like this
In your splash activity I have a method like :
#Override
public void loadLoginScreen() {
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
finish();
}
Then in Login activity (i am using firebase so i check if the user is null or not you may apply your logic to check the same )
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Get Firebase auth instance
if (auth.getCurrentUser() != null) {
startActivity(new Intent(LoginActivity.this, HomeScreenActivity.class));
finish();
}
// set the view now
setContentView(R.layout.activity_login);
}
and when I do the logout I do somewhat like this
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.milogout:
FirebaseAuth.getInstance().signOut();
startActivity(LoginActivity.class);
finish();
break;
}
return true;
}
Previous activities need to be finished on moving to Dashboard. Call before starting new activity of Dashboard
finishAffinity();
This finish current activity as well as all activities immediately below it.
I want to be able to switch between my app and twitters app to show a search for a pre-determined hashtag.
I have an on click listener & sending the user to the twitter app... loading the tweets and allowing the discussion of that hashtag. There is the logic but how can I do this? What I get now is just my feed and a drop down list of previous searches.
Here is the listener & intent code:
final Button button = (Button) view.findViewById(R.id.C_Twitter_Button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("twitter://search?f=realtime&q=%23KeyWord"));
startActivity(intent);
}catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://twitter.com/search?f=realtime&q=%23KeyWord")));
}
}
});
Can anyone offer me a solution?
Thanks
The search query was wrong :(
The solution is to use the following url to search the twitter app:
twitter://search?query=%23hashtag
Cheers
In my Android app, I have a button with the background image of an Amazon.com product (let's say a shirt or something), and when clicked I would like it to open in the Amazon app (com.amazon.mShop.android) if is already installed rather than in the browser, and in the browser if the app is not installed.
I have been able to find how to add a deep link to a specific Amazon client app, but not how to link to a specific item that would open with open with the Amazon app.
Currently, my click listener opens in a browser by doing the following:
b3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(urlOfItemOnAmazonSite));
startActivity(intent);
}
})
The Amazon developer's home page is probably the best place for this answer. This may be a good start: https://developer.amazon.com/public/apis/earn/in-app-purchasing/docs/deeplink#Link%20Configuration. Here they explain how to construct the Uri you'll need to use to set the Intent data.
Of course, you may want to be careful and wrap startActivity in a try/catch in case Amazon isn't installed and it throws an ActivityNotFoundException
You can simply do the following:
b3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Uri uri=Uri.parse(productUrl);
Intent intent=new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
})
//Note extract url of product store in var productUrl(or any other var) and //parse it.
I am building a login system in android and i need to accomplish the following:
save userdata on the local storage
when a user is created and i press on the button it needs to dynamically create a radiobutton with the user name and short name in it.
I have already managed to accomplish these things, but the only problem i have now is that i want to to have 2 classes, one where you register your account and the other where the radiobuttons with the user data is displayed. So my question: how can i program the calss in such a way that when i press on the register button that it creates the radiobuttons in a different class.
beneath is the code of the classes:
enter code here
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.Save:
Intent I = new Intent();
I.putExtra(
I.setClass(this, ShowUsers.class);
startActivity(I);
break;
}
}
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Start other Activity
switch (v.getId()) {
case R.id.create:
Intent intent = new Intent();
intent.setClass(Main.this, Register.class);
startActivity(intent);
break;
}
Bundle extras = getIntent().getExtras();
String userName;
if (extras != null) {
userName = extras.getString("editTextName,editTextPassword,editTextshortname");
// and get whatever type user account id is
}
}
}
when i click the save button it needs to create the radio button in the main class, now the question is how can i accomplish this?
If the second class is an Activity, then one solution is to send it an Intent with the data it needs to create the radio buttons. You do this by creating an Intent object, calling any of its setExtra() methods, then calling startActivity() with the Intent. Check out the Android API docs for more details.
I have a simple app that I'm putting together for my company. I have 4 buttons that I've created but can't seem to get them to link correctly. One button should open our mobile site, another button to call us, another button to map to us, and the final button linked to our "News" site. Any help would be greatly appreciated!
On your buttons, you should set OnClickListener, and to do some required actions you could see the example below:
To Open a Map with Certain Location
mapButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + your-location-geo-address));
startActivity(i);
}
});
To call certain number
callButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + telephone-number));
startActivity(i);
}
});
To open a website
linkButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(website-address));
startActivity(i);
}
});
Change "location-address", "telephone-number", and "website-address" with your own String value.
I hope this helps.
anmustangs answer is very good, but one thing I would like to add for the button you are making for a link to your site, where anmustangs wrote (website-address) instead of just typing in a site, it needs to put formatted correctly. For example, you can use "http://www.google.com" and yes you do need to use the quotation marks I put in there. I know I am years late to this thread but who knows who my post may help.