Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Empowering you to understand your world

How To Start A New Activity In Android

By Nicholas Brown.

In Android, apps have multiple screens called ‘activities’. When you see a new screen come up, it is launching a new activity. Launching an activity is quite simple in Android, as shown below.

To create an activity in Android, right click ‘app’ under the project tab of your app, then click New > Activity > Empty Activity. It doesn’t have to be an empty activity but it is the simplest type of activity to start with if you’re just getting started with Android app development.

Name your activity in a manner that clearly distinguishes its purpose from the other parts of your app. For this example, the activity name will be ViewProfile. Once you have created your new activity, you can create a button to launch it and then adding the following line of code to the button’s XML code block:

android:onClick="LaunchProfile"

Now go over to the Java source file of the activity your activity launcher button is in, which might be something like ‘MainActivity.java’ if you didn’t change the default name. Create a function called ‘LaunchProfile’, and inside that is where you’ll type the code required to actually launch the ‘ViewProfile’ activity:

Intent ProfileLauncher = new Intent(this, ViewProfile.class);
startActivity(ProfileLauncher);

When you click your new launch button, you should see that activity pop up. When the need arises, you can also send a message to the activity you are launching using ‘intent.PutExtra’, as shown in the Android documentation.

Leave a Reply

Subscribe to our newsletter
Get notified when new content is published