This question already has an answer here:
Which is the best way to add a button?
(1 answer)
Closed 7 years ago.
I am very new to android development and I am having problem displaying a new button to a activity which has already run. I am using this tutorial http://developer.android.com/training/basics/firstapp/starting-activity.html. Here they display Hello World in the new activity. I would like to add a button called "SKIP"! So that the user can go to a another new activity called Functions. How do I do that with the intent? My intent is already being used to display the string hello world! I am using android studio.
Appreciate any help thanks
To create a button you need to go to your main XML file, add a button. Then in your Activity create a onClick listener for the button.
When it comes to going to another activity you need to create a new Intent with
Intent intent = new Intent(this, Functions.class);
startActivity(intent)
You would call your new activity with the following snippet within the OnClickListener of your button:
Intent intent = new Intent(this, Functions.class);
startActivity(intent);
And define your Functions class in your AndroidManifest.xml file similar to what the originally defined Activity is defined as. But you should only have one launcher Activity.
Related
This question already has answers here:
Insert a new contact intent
(9 answers)
Closed 5 years ago.
I need to open "Add new contact" page in phone. I searched for relevant Android code. But i didn't get results. please somebody help me by posting the code for opening add new contact page in Android phone programatically(I just need to open alone).
For this you have to create one activity with all the parameters you want like name, phone number etc.
If you want to open this page only then you are done, but if want to open this activity from any other activity then declare this activity in android manifest inside application tag like below:
<activity android:name="MainActivity"></activity>
After this, create Intent in your class from where you want to open this activity like:
Intent intent = new Intent(Activity1.this, MainActivity.class)
startActivity(intent)
This question already has answers here:
Using Intent in an Android application to show another activity
(11 answers)
Closed 7 years ago.
How can I pass the control from one Activity to another using the explicit Intent?
I had an issue in androidManifest.xmnl as it marked the Mainactivity file As an error.
If you just want to navigate from one activity to another you can use explicit intent as :
Intent next = new Intent(YourCurrentActivity.this , NextActivity.class);
startActivity(next);
This question already has answers here:
How to close activity and go back to previous activity in android
(19 answers)
Closed 8 years ago.
I have a class TestFragment which extends Fragment,from this Fragment I have started Activity1
and from Activity1 i have started Activity2,Now i am in Activity2 want to go to TestFragment
when a button inside Activity2 is clicked and i want to update the UI in TestFragment
Call finish() if you want to go back to the caller activity. If you want to launch the activity which contains the fragment create an intent and launch the activity, something like startActivity(new Intent(this,youractivity.class));
Please write some code..Anyway if you want start another activity take a look here: http://developer.android.com/training/basics/firstapp/starting-activity.html onClick event you just put the intent for example Intent intent = new Intent(this, TestFragment.class);
you can clear the stack activity like this:
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
by this code you will clear the stack and MainActivity will be opend.
Hope this help you
I made an android app but I wanted to start a new activity (.xml).
Normally when an app starts it shows direct the activity_main.xml layout file.
I don't know how that is going on so what's the code for this because so I know how to start a new activity.
Simple u have need in main activity :-
{
(R.layout.main_activity);
Intent intent =new Intent(getApplicationContext(),AnotherActivity.class);
startActivity(intent);
}
and then you have create `AnotherActivity.class
and insert another layout for AnotherActivity in (R.layout.anotherlayout);
that solve
You can specify the layout you want to show in your Activity using setContentView method:
setContentView(R.layout.layoutForYourActivity);
This has to be specified inside your onCreate method
Create a new activity through New -> Other -> Android -> Android Activity
A activity is a .java file, the .xml is only the layout.
Call the new activity with
intent = new Intent(main.this, YourActivity.class);
startActivity(intent);
I suggest you to do some basic tutorials.
I'm new to android. Please tell me how to navigate to a new page in android.
Thanks in advance.
Edit:How to start a new activity from an existing activity
In android to navigate to another page means you have to start another activity. for starting a new activity use this
Intent intent = new Intent(currentActivity.this, nextActivity.class);
startActivity(intent);
You should mention the next activity in the AndroidManifest file.
To change your page (i think you're refering to "Activities" in android you need to issue a so called "intent").
You cann do that by:
startActivity(new Intent(nextactivity,NextActivity.class));
or
startActivityForResult(new Intent(nextactivity,NextActivity.class),1);
if you want the new Activity to return any result to the activity who started the new one.
But what i recommend is, that you read this documentation here:
http://developer.android.com/guide/topics/intents/intents-filters.html
and come back to this question if you have need additional assistance on concrete problems on that topics.
i hope that helps.